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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 08:23:25 PST 2026


================
@@ -594,12 +595,46 @@ 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));
+
+        VPValue *LaneOffset;
+        if (BaseIVTy->isFloatingPointTy()) {
+          LaneOffset =
+              Plan.getOrAddLiveIn(ConstantFP::get(BaseIVTy, KnownLane));
+        } else {
+          unsigned BaseIVBits = BaseIVTy->getScalarSizeInBits();
+          LaneOffset = Plan.getConstantInt(APInt(BaseIVBits, KnownLane,
+                                                 /*isSigned*/ false,
+                                                 /*implicitTrunc*/ true));
+        }
+
+        VPBuilder LaneBuilder(DefR);
+        VPValue *StartIndex = Steps->getStartIndex();
+        if (!StartIndex && Steps->getInductionOpcode() == Instruction::FSub)
+          StartIndex = Plan.getOrAddLiveIn(ConstantFP::getNullValue(BaseIVTy));
+
+        if (StartIndex) {
+          unsigned InductionOpcode = BaseIVTy->isFloatingPointTy()
+                                         ? Steps->getInductionOpcode()
+                                         : Instruction::Add;
+          LaneOffset = LaneBuilder.createNaryOp(
+              InductionOpcode, {StartIndex, LaneOffset},
+              BaseIVTy->isFloatingPointTy()
+                  ? VPIRFlags(FastMathFlags())
+                  : VPIRFlags(VPIRFlags::WrapFlagsTy(false, false)));
----------------
fhahn wrote:

Updated, thanks

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


More information about the llvm-commits mailing list