summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp')
-rw-r--r--llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index f4a1f58debba..41f13cc2d9a9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2958,11 +2958,20 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
- Instruction *I = getInsertPos();
+ Instruction *InsertPos = getInsertPos();
+ // Find the VPValue index of the interleave group. We need to skip gaps.
+ unsigned InsertPosIdx = 0;
+ for (unsigned Idx = 0; IG->getFactor(); ++Idx)
+ if (auto *Member = IG->getMember(Idx)) {
+ if (Member == InsertPos)
+ break;
+ InsertPosIdx++;
+ }
Type *ValTy = Ctx.Types.inferScalarType(
- getNumDefinedValues() > 0 ? getVPValue(0) : getStoredValues()[0]);
+ getNumDefinedValues() > 0 ? getVPValue(InsertPosIdx)
+ : getStoredValues()[InsertPosIdx]);
auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
- unsigned AS = getLoadStoreAddressSpace(I);
+ unsigned AS = getLoadStoreAddressSpace(InsertPos);
enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
unsigned InterleaveFactor = IG->getFactor();
@@ -2976,8 +2985,8 @@ InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
// Calculate the cost of the whole interleaved group.
InstructionCost Cost = Ctx.TTI.getInterleavedMemoryOpCost(
- I->getOpcode(), WideVecTy, IG->getFactor(), Indices, IG->getAlign(), AS,
- CostKind, getMask(), NeedsMaskForGaps);
+ InsertPos->getOpcode(), WideVecTy, IG->getFactor(), Indices,
+ IG->getAlign(), AS, CostKind, getMask(), NeedsMaskForGaps);
if (!IG->isReverse())
return Cost;