[llvm] [VPlan] Replicate VPScalarIVStepsRecipe by VF outside replicate regions. (PR #170053)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 07:51:37 PST 2026


================
@@ -594,12 +595,36 @@ cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
                                 /*IsSingleScalar=*/true, /*Mask=*/nullptr,
                                 *RepR, *RepR, RepR->getDebugLoc());
   } else {
-    assert(isa<VPInstruction>(DefR) &&
-           "DefR must be a VPReplicateRecipe or VPInstruction");
     New = DefR->clone();
     for (const auto &[Idx, Op] : enumerate(NewOps)) {
       New->setOperand(Idx, Op);
     }
+    if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(New)) {
+      // Skip lane 0: an absent start index is implicitly zero.
+      unsigned KnownLane = Lane.getKnownLane();
+      if (KnownLane != 0) {
+        VPTypeAnalysis TypeInfo(Plan);
+        Type *BaseIVTy = TypeInfo.inferScalarType(DefR->getOperand(0));
+        unsigned BaseIVBits = BaseIVTy->getScalarSizeInBits();
+        VPBuilder LaneBuilder(DefR);
+        VPValue *LaneOffset =
+            Plan.getConstantInt(APInt(IdxTy->getScalarSizeInBits(), KnownLane)
+                                    .zextOrTrunc(BaseIVBits));
+
+        if (BaseIVTy->isFloatingPointTy())
+          LaneOffset = LaneBuilder.createScalarCast(
+              Instruction::SIToFP, LaneOffset, BaseIVTy, Steps->getDebugLoc());
+
+        if (VPValue *StartIndex = Steps->getStartIndex()) {
+          LaneOffset = BaseIVTy->isFloatingPointTy()
+                           ? LaneBuilder.createNaryOp(Instruction::FAdd,
+                                                      {StartIndex, LaneOffset},
+                                                      FastMathFlags())
----------------
ayalz wrote:

Given that no FMF are set, wonder if a common
```
        if (VPValue *StartIndex = Steps->getStartIndex()) {
          VPBuilder LaneBuilder(DefR);
          LaneOffset = LaneBuilder.createNaryOp(InductionOpcode, {StartIndex, LaneOffset});
        }
```
would work for both FP and non-FP, or whether the latter requires explicit `Instruction::Add` as set by VPScalarIVStepsRecipe::execute()?

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


More information about the llvm-commits mailing list