Handle extract instructions in the lGetBasePtrAndOffsets() pattern matching code.

This commit is contained in:
Matt Pharr
2012-03-05 09:20:45 -08:00
parent b7df312ca7
commit e013e0a374

23
opt.cpp
View File

@@ -1117,6 +1117,20 @@ lGetConstantAddExprBaseOffset(llvm::Constant *op0, llvm::Constant *op1,
}
static llvm::Value *
lExtractFromInserts(llvm::Value *v, unsigned int index) {
llvm::InsertValueInst *iv = llvm::dyn_cast<llvm::InsertValueInst>(v);
if (iv == NULL)
return NULL;
Assert(iv->hasIndices() && iv->getNumIndices() == 1);
if (iv->getIndices()[0] == index)
return iv->getInsertedValueOperand();
else
return lExtractFromInserts(iv->getAggregateOperand(), index);
}
/** Given a varying pointer in ptrs, this function checks to see if it can
be determined to be indexing from a common uniform base pointer. If
so, the function returns the base pointer llvm::Value and initializes
@@ -1232,6 +1246,15 @@ lGetBasePtrAndOffsets(llvm::Value *ptrs, llvm::Value **offsets,
return base;
}
llvm::ExtractValueInst *ev = llvm::dyn_cast<llvm::ExtractValueInst>(ptrs);
if (ev != NULL) {
Assert(ev->getNumIndices() == 1);
int index = ev->getIndices()[0];
ptrs = lExtractFromInserts(ev->getAggregateOperand(), index);
if (ptrs != NULL)
return lGetBasePtrAndOffsets(ptrs, offsets, insertBefore);
}
return NULL;
}