[PATCH] D132566: [SLP] Fix cost model w.r.t. operand properties
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 23 08:40:55 PDT 2022
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42ef5720493e: [SLP] Fix cost model w.r.t. operand properties (authored by reames).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132566/new/
https://reviews.llvm.org/D132566
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
@@ -6550,32 +6550,26 @@
case Instruction::And:
case Instruction::Or:
case Instruction::Xor: {
- TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None};
-
- // Certain instructions can be cheaper to vectorize if they have a
- // constant second vector operand.
const unsigned OpIdx = isa<BinaryOperator>(VL0) ? 1 : 0;
- auto Op2Info = getOperandInfo(VL, OpIdx);
- SmallVector<const Value *, 4> Operands(VL0->operand_values());
- InstructionCost ScalarEltCost =
+ InstructionCost ScalarCost = 0;
+ for (auto *V : VL) {
+ auto *VI = cast<Instruction>(V);
+ TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(VI->getOperand(0));
+ TTI::OperandValueInfo Op2Info = TTI::getOperandInfo(VI->getOperand(OpIdx));
+ SmallVector<const Value *, 4> Operands(VI->operand_values());
+ ScalarCost +=
TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind,
- Op1Info, Op2Info,
- Operands, VL0);
- if (NeedToShuffleReuses) {
- CommonCost -= (EntryVF - VL.size()) * ScalarEltCost;
+ Op1Info, Op2Info, Operands, VI);
}
- 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);
+ if (NeedToShuffleReuses) {
+ CommonCost -= (EntryVF - VL.size()) * ScalarCost/VL.size();
}
+ TTI::OperandValueInfo Op1Info = getOperandInfo(VL, 0);
+ TTI::OperandValueInfo Op2Info = getOperandInfo(VL, OpIdx);
InstructionCost VecCost =
TTI->getArithmeticInstrCost(E->getOpcode(), VecTy, CostKind,
- Op1Info, Op2Info,
- Operands, VL0);
+ Op1Info, Op2Info);
LLVM_DEBUG(dumpTreeCosts(E, CommonCost, VecCost, ScalarCost));
return CommonCost + VecCost - ScalarCost;
}
@@ -6640,16 +6634,18 @@
auto *SI =
cast<StoreInst>(IsReorder ? VL[E->ReorderIndices.front()] : VL0);
Align Alignment = SI->getAlign();
+ InstructionCost ScalarStCost = 0;
+ for (auto *V : VL) {
+ auto *VI = cast<Instruction>(V);
+ TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(VI->getOperand(0));
+ ScalarStCost +=
+ TTI->getMemoryOpCost(Instruction::Store, ScalarTy, Alignment, 0,
+ CostKind, OpInfo, VI);
+ }
TTI::OperandValueInfo OpInfo = getOperandInfo(VL, 0);
- InstructionCost ScalarEltCost = TTI->getMemoryOpCost(
- Instruction::Store, ScalarTy, Alignment, 0, CostKind, OpInfo, VL0);
- InstructionCost ScalarStCost = VecTy->getNumElements() * ScalarEltCost;
- TTI::OperandValueKind OpVK = TTI::OK_AnyValue;
- if (OpInfo.isConstant())
- OpVK = TTI::OK_NonUniformConstantValue;
- InstructionCost VecStCost = TTI->getMemoryOpCost(
- Instruction::Store, VecTy, Alignment, 0, CostKind,
- {OpVK, TTI::OP_None}, VL0);
+ InstructionCost VecStCost =
+ TTI->getMemoryOpCost(Instruction::Store, VecTy, Alignment, 0, CostKind,
+ OpInfo);
LLVM_DEBUG(dumpTreeCosts(E, CommonCost, VecStCost, ScalarStCost));
return CommonCost + VecStCost - ScalarStCost;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132566.462507.patch
Type: text/x-patch
Size: 3843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220923/e3b204d0/attachment.bin>
More information about the llvm-commits
mailing list