[llvm] de7e3a5 - [VPlan] Compute cost of scalar (U|S)Div, (U|S)Rem in computeCost (NFCI).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 13 14:09:37 PDT 2025


Author: Florian Hahn
Date: 2025-09-13T22:09:06+01:00
New Revision: de7e3a589525179f3b02b84b194aac6cf581425c

URL: https://github.com/llvm/llvm-project/commit/de7e3a589525179f3b02b84b194aac6cf581425c
DIFF: https://github.com/llvm/llvm-project/commit/de7e3a589525179f3b02b84b194aac6cf581425c.diff

LOG: [VPlan] Compute cost of scalar (U|S)Div, (U|S)Rem in computeCost (NFCI).

Directly compute the cost of UDiv, SDiv, URem, SRem in VPlan.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index c6273074778d1..f5c8cf106d8b5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3151,9 +3151,23 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
   case Instruction::Xor:
   case Instruction::ICmp:
   case Instruction::FCmp:
+  case Instruction::Select:
     return *getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
                                        Ctx) *
            (isSingleScalar() ? 1 : VF.getFixedValue());
+  case Instruction::SDiv:
+  case Instruction::UDiv:
+  case Instruction::SRem:
+  case Instruction::URem: {
+    InstructionCost ScalarCost = *getCostForRecipeWithOpcode(
+        getOpcode(), ElementCount::getFixed(1), Ctx);
+    if (isSingleScalar())
+      return ScalarCost;
+
+    return ScalarCost * VF.getFixedValue() +
+           Ctx.getScalarizationOverhead(Ctx.Types.inferScalarType(this),
+                                        to_vector(operands()), VF);
+  }
   case Instruction::Load:
   case Instruction::Store: {
     if (isSingleScalar()) {


        


More information about the llvm-commits mailing list