Fix bugs in LLVMExtractFirstVectorElement().

When we're manually scalarizing the extraction of the first element
of a vector value, we need to be careful about handling constant values
and about where new instructions are inserted.  The old code was
sloppy about this, which in turn lead to invalid IR in some cases.
For example, the two bugs below were essentially due to generating
an extractelement inst from a zeroinitializer value and then inserting
it in the wrong bblock such that a phi node that used that value was
malformed.

Fixes issues #240 and #229.
This commit is contained in:
Matt Pharr
2012-04-19 09:45:04 -07:00
parent a2bb899a6b
commit 326c45fa17
3 changed files with 52 additions and 26 deletions

View File

@@ -2295,8 +2295,7 @@ struct GatherImpInfo {
static llvm::Value *
lComputeCommonPointer(llvm::Value *base, llvm::Value *offsets,
llvm::Instruction *insertBefore) {
llvm::Value *firstOffset = LLVMExtractFirstVectorElement(offsets,
insertBefore);
llvm::Value *firstOffset = LLVMExtractFirstVectorElement(offsets);
return lGEPInst(base, firstOffset, "ptr", insertBefore);
}
@@ -3290,8 +3289,7 @@ lComputeBasePtr(llvm::CallInst *gatherInst, llvm::Instruction *insertBefore) {
// All of the variable offsets values should be the same, due to
// checking for this in GatherCoalescePass::runOnBasicBlock(). Thus,
// extract the first value and use that as a scalar.
llvm::Value *variable = LLVMExtractFirstVectorElement(variableOffsets,
insertBefore);
llvm::Value *variable = LLVMExtractFirstVectorElement(variableOffsets);
if (variable->getType() == LLVMTypes::Int64Type)
offsetScale = new llvm::ZExtInst(offsetScale, LLVMTypes::Int64Type,
"scale_to64", insertBefore);