[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
Tue Aug 30 12:41:53 PDT 2022


fhahn created this revision.
fhahn added reviewers: ABataev, spatel, RKSimon, wjschmidt, dmgreen.
Herald added subscribers: vporpo, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

Depends on D132966 <https://reviews.llvm.org/D132966>.


Repository:
  rG LLVM Github Monorepo

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
@@ -6434,24 +6434,35 @@
       auto Op2Info = getOperandInfo(VL, OpIdx, /*EnableFP=*/false);
 
       SmallVector<const Value *, 4> Operands(VL0->operand_values());
-      InstructionCost ScalarEltCost =
-          TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind,
-                                      Op1Info, Op2Info,
-                                      Operands, VL0);
+      InstructionCost ScalarCost = 0;
+      for (unsigned i = 0, e = VL.size(); i < e; ++i)
+        ScalarCost += TTI->getArithmeticInstrCost(
+            E->getOpcode(), ScalarTy, CostKind, Op1Info, Op2Info, Operands,
+            isa<Instruction>(VL[i]) ? cast<Instruction>(VL[i]) : 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 (unsigned I = 1; I != VL.size(); ++I)
+        OpsForVector.push_back(cast<Instruction>(VL[I]));
+
       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.456762.patch
Type: text/x-patch
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220830/93af6486/attachment.bin>


More information about the llvm-commits mailing list