[llvm] [VPlan] Sink retrieving legacy costs to more specific computeCost impls. (PR #109708)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 14:32:35 PDT 2024


================
@@ -311,10 +306,12 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) {
 
 InstructionCost VPRecipeBase::computeCost(ElementCount VF,
                                           VPCostContext &Ctx) const {
-  // Compute the cost for the recipe falling back to the legacy cost model using
-  // the underlying instruction. If there is no underlying instruction, returns
-  // 0.
-  Instruction *UI = getInstructionForCost(this);
+  llvm_unreachable("subclasses should implement computeCost");
+}
+
+InstructionCost VPSingleDefRecipe::computeCost(ElementCount VF,
+                                               VPCostContext &Ctx) const {
+  Instruction *UI = dyn_cast_or_null<Instruction>(getUnderlyingValue());
   if (UI && isa<VPReplicateRecipe>(this)) {
----------------
ayalz wrote:

Note that replicate recipes by definition must have a UI, so the latter can be asserted instead of checked.

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


More information about the llvm-commits mailing list