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

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 17:07:58 PST 2025


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

- 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.

>From 5329349c9d0859dd138cc76a87293a837d63c09d Mon Sep 17 00:00:00 2001
From: Hassnaa Hamdi <hassnaa.hamdi at arm.com>
Date: Thu, 30 Jan 2025 00:57:33 +0000
Subject: [PATCH] [LV]: Add costs to VPInstruction

- 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.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 3 +++
 1 file changed, 3 insertions(+)

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;
   }
 



More information about the llvm-commits mailing list