[llvm] [VPlan] First step towards VPlan cost modeling. (PR #67934)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 07:43:35 PDT 2024


================
@@ -7395,6 +7396,177 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
   return VF;
 }
 
+static InstructionCost
+computeCostForRecipe(VPRecipeBase *R, ElementCount VF,
+                     SmallPtrSetImpl<Instruction *> &SeenUI,
+                     LoopVectorizationCostModel &CM,
+                     const TargetTransformInfo &TTI, VPCostContext CostCtx) {
+  Instruction *UI = nullptr;
+  if (auto *S = dyn_cast<VPSingleDefRecipe>(R))
+    UI = dyn_cast_or_null<Instruction>(S->getUnderlyingValue());
+  if (UI && (CM.VecValuesToIgnore.contains(UI) || !SeenUI.insert(UI).second))
----------------
fhahn wrote:

> If VecValuesToIgnore contains UI, was it ignored? Can this be an assert?

As this function computes the cost below, that should be ensured currently. Added asserts that no reduction/induction insts are in CM.VecValuesToIgnore.

> SeenUI: only one - the first - recipe holding the same underlying Instruction carries a cost? This ensures an underlying Inst cost is counted once, but if multiple recipes hold it (what/are there such cases?), all but the first are Valid cost free? This also takes care of IVInc instructions whose cost is counted elsewhere, and should not be counted here (although could discount their cost there, to keep it simple here?).

Insertion should not be needed, removed!

https://github.com/llvm/llvm-project/pull/67934


More information about the llvm-commits mailing list