[llvm] ba4ce60 - [LV] Add scalar load/stores to VPReplicateRecipe::computeCost (#153218)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 5 03:52:11 PDT 2025


Author: David Sherwood
Date: 2025-09-05T11:52:07+01:00
New Revision: ba4ce60f1a08d5f7f967c733b2225e6f0269411d

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

LOG: [LV] Add scalar load/stores to VPReplicateRecipe::computeCost (#153218)

Avoid calling getLegacyCost for single scalar loads and stores where the
cost is trivial to calculate.

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 5f3503d0ce57a..46162a9276469 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3158,6 +3158,24 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
     return *getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
                                        Ctx) *
            (isSingleScalar() ? 1 : VF.getFixedValue());
+  case Instruction::Load:
+  case Instruction::Store: {
+    if (isSingleScalar()) {
+      bool IsLoad = UI->getOpcode() == Instruction::Load;
+      Type *ValTy = Ctx.Types.inferScalarType(IsLoad ? this : getOperand(0));
+      Type *ScalarPtrTy = Ctx.Types.inferScalarType(getOperand(IsLoad ? 0 : 1));
+      const Align Alignment = getLoadStoreAlignment(UI);
+      unsigned AS = getLoadStoreAddressSpace(UI);
+      TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(UI->getOperand(0));
+      InstructionCost ScalarMemOpCost = Ctx.TTI.getMemoryOpCost(
+          UI->getOpcode(), ValTy, Alignment, AS, Ctx.CostKind, OpInfo, UI);
+      return ScalarMemOpCost + Ctx.TTI.getAddressComputationCost(
+                                   ScalarPtrTy, nullptr, nullptr, Ctx.CostKind);
+    }
+    // TODO: See getMemInstScalarizationCost for how to handle replicating and
+    // predicated cases.
+    break;
+  }
   }
 
   return Ctx.getLegacyCost(UI, VF);


        


More information about the llvm-commits mailing list