[llvm] [LV]: Add costs to VPInstruction (PR #125008)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 17:08:33 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Hassnaa Hamdi (hassnaaHamdi)

<details>
<summary>Changes</summary>

- As VPlanTransforms replaces some instructions by VPInstructions, then VPInstruction should have costs.
- Use legacy model for now.
- Computed costs are for the original/replaced instructions to match with what legacy model computed.

---
Full diff: https://github.com/llvm/llvm-project/pull/125008.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+3) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a1ff684b2b8017..8813ea3c208b61 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1315,6 +1315,9 @@ class VPInstruction : public VPRecipeWithIRFlags,
   InstructionCost computeCost(ElementCount VF,
                               VPCostContext &Ctx) const override {
     // TODO: Compute accurate cost after retiring the legacy cost model.
+    // Use legacy cost model for now.
+    if (auto *I = dyn_cast_or_null<Instruction>(getUnderlyingValue()))
+      return Ctx.getLegacyCost(I, VF);
     return 0;
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list