[PATCH] D132967: [SLP] Pass full scalar and vector context instructions to TTI.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 08:32:55 PDT 2022
fhahn updated this revision to Diff 456976.
fhahn added a comment.
Address latest comments, thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132967/new/
https://reviews.llvm.org/D132967
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6437,24 +6437,36 @@
auto Op2Info = getOperandInfo(VL, OpIdx);
SmallVector<const Value *, 4> Operands(VL0->operand_values());
- InstructionCost ScalarEltCost =
- TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind,
- Op1Info, Op2Info,
- Operands, VL0);
+ InstructionCost ScalarCost = 0;
+ for (const Value *V : VL) {
+ ScalarCost += TTI->getArithmeticInstrCost(
+ E->getOpcode(), ScalarTy, CostKind, Op1Info, Op2Info, Operands,
+ isa<Instruction>(V) ? cast<Instruction>(V) : nullptr);
+ }
+
if (NeedToShuffleReuses) {
- CommonCost -= (EntryVF - VL.size()) * ScalarEltCost;
+ CommonCost -=
+ (EntryVF - VL.size()) *
+ TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind,
+ Op1Info, Op2Info, Operands);
}
- InstructionCost ScalarCost = VecTy->getNumElements() * ScalarEltCost;
+
for (unsigned I = 0, Num = VL0->getNumOperands(); I < Num; ++I) {
if (all_of(VL, [I](Value *V) {
return isConstant(cast<Instruction>(V)->getOperand(I));
}))
Operands[I] = ConstantVector::getNullValue(VecTy);
}
+
+ // Populate vector with context instructions.
+ SmallVector<const Instruction *> OpsForVector = {VL0};
+ for (const Value *V : VL.drop_front())
+ OpsForVector.push_back(cast<Instruction>(V));
+
InstructionCost VecCost =
- TTI->getArithmeticInstrCost(E->getOpcode(), VecTy, CostKind,
- Op1Info, Op2Info,
- Operands, VL0);
+ TTI->getArithmeticInstrCost(E->getOpcode(), VecTy, CostKind, Op1Info,
+ Op2Info, Operands, OpsForVector);
+
LLVM_DEBUG(dumpTreeCosts(E, CommonCost, VecCost, ScalarCost));
return CommonCost + VecCost - ScalarCost;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132967.456976.patch
Type: text/x-patch
Size: 2262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220831/88973625/attachment.bin>
More information about the llvm-commits
mailing list