[llvm] [SLP] Use costing to decide between Strided Loads and Compressed Loads (PR #226540)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 12:00:29 PDT 2026


================
@@ -61,6 +61,49 @@ InstructionCost getShuffleCost(const TargetTransformInfo &TTI,
                             /*CtxI=*/nullptr, VIC);
 }
 
+InstructionCost
+getStridedLoadCost(const TargetTransformInfo &TTI, Type *StridedLoadTy,
+                   Type *VecTy, Value *Ptr, Align CommonAlignment,
+                   TargetTransformInfo::CastContextHint Ctx,
+                   TargetTransformInfo::TargetCostKind CostKind) {
+  InstructionCost StridedCost = TTI.getMemIntrinsicInstrCost(
+      MemIntrinsicCostAttributes(Intrinsic::experimental_vp_strided_load,
+                                 StridedLoadTy, Ptr,
+                                 /*VariableMask=*/false, CommonAlignment),
+      CostKind);
+  if (StridedLoadTy != VecTy)
+    StridedCost += TTI.getCastInstrCost(Instruction::BitCast, VecTy,
+                                        StridedLoadTy, Ctx, CostKind);
+  return StridedCost;
+}
+
+InstructionCost
+getCompressedLoadCost(const TargetTransformInfo &TTI, const LoadInst *LI0,
+                      const CompressedLoadInfo &Info,
+                      TargetTransformInfo::TargetCostKind CostKind) {
+  if (Info.InterleaveFactor)
+    return TTI.getInterleavedMemoryOpCost(
+        Instruction::Load, Info.LoadVecTy, Info.InterleaveFactor, {},
+        LI0->getAlign(), LI0->getPointerAddressSpace(), CostKind);
+
+  InstructionCost Cost;
+  if (Info.IsMasked) {
+    Cost = TTI.getMemIntrinsicInstrCost(
+        MemIntrinsicCostAttributes(Intrinsic::masked_load, Info.LoadVecTy,
+                                   LI0->getAlign(),
+                                   LI0->getPointerAddressSpace()),
+        CostKind);
+  } else {
+    Cost = TTI.getMemoryOpCost(
+        Instruction::Load, Info.LoadVecTy, LI0->getAlign(),
+        LI0->getPointerAddressSpace(), CostKind,
+        TargetTransformInfo::getOperandInfo(LI0->getPointerOperand()));
+  }
+  Cost += getShuffleCost(TTI, TTI::SK_PermuteSingleSrc, Info.LoadVecTy,
+                         CostKind, Info.CompressMask);
----------------
alexey-bataev wrote:

Lost `// TODO: include this cost into CommonCost.`

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


More information about the llvm-commits mailing list