Add LLVMExtractFirstVectorElement() function (and use it).
For cases where it turns out that we just need the first element of a vector (e.g. because we've determined that all of the values are equal), it's often more efficient to only compute that one value with scalar operations than to compute the whole vector's worth and then just use one value. This function tries to rewrite a vector computation to the scalar equivalent, if possible. (Partial work-around to http://llvm.org/bugs/show_bug.cgi?id=11775.) Note that sometimes this is the wrong thing to do--if we need the entire vector value for other purposes, for example.
This commit is contained in:
10
opt.cpp
10
opt.cpp
@@ -2531,9 +2531,8 @@ struct GatherImpInfo {
|
||||
static llvm::Value *
|
||||
lComputeCommonPointer(llvm::Value *base, llvm::Value *offsets,
|
||||
llvm::Instruction *insertBefore) {
|
||||
llvm::Value *firstOffset =
|
||||
llvm::ExtractElementInst::Create(offsets, LLVMInt32(0), "first_offset",
|
||||
insertBefore);
|
||||
llvm::Value *firstOffset = LLVMExtractFirstVectorElement(offsets,
|
||||
insertBefore);
|
||||
return lGEPInst(base, firstOffset, "ptr", insertBefore);
|
||||
}
|
||||
|
||||
@@ -3524,9 +3523,8 @@ 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 =
|
||||
llvm::ExtractElementInst::Create(variableOffsets, LLVMInt32(0),
|
||||
"variable0", insertBefore);
|
||||
llvm::Value *variable = LLVMExtractFirstVectorElement(variableOffsets,
|
||||
insertBefore);
|
||||
if (variable->getType() == LLVMTypes::Int64Type)
|
||||
offsetScale = new llvm::ZExtInst(offsetScale, LLVMTypes::Int64Type,
|
||||
"scale_to64", insertBefore);
|
||||
|
||||
Reference in New Issue
Block a user