[llvm] [VPlan] Materialize VPFirstOrderRecurrencePHIRecipe start value in VPlan (PR #171590)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 09:39:52 PDT 2026


================
@@ -4265,6 +4269,27 @@ void VPlanTransforms::adjustFirstOrderRecurrenceMiddleUsers(VPlan &Plan,
     assert(VectorRegion->getSingleSuccessor() == Plan.getMiddleBlock() &&
            "Cannot handle loops with uncountable early exits");
 
+    // Adjust start value of fixed-order recurrence phi to [poison, ... ,
+    // poison, start value] for vector VF plans.
+    if (!ScalarVFOnly) {
+      VPValue *StartV = FOR->getStartValue();
+      DebugLoc DL = FOR->getDebugLoc();
+      VPValue *Poison =
+          Plan.getOrAddLiveIn(PoisonValue::get(StartV->getScalarType()));
+      // TODO: Use the type of runtimeVF as index type.
+      Type *IdxTy = Type::getInt32Ty(Plan.getContext());
+      VPValue *RuntimeVF =
+          PHBuilder.createScalarZExtOrTrunc(&Plan.getVF(), IdxTy, DL);
+      // TODO: Set nowrap flag for LastIdx.
+      VPValue *LastIdx = PHBuilder.createOverflowingOp(
+          Instruction::Sub, {RuntimeVF, Plan.getConstantInt(IdxTy, 1)},
+          {false, false}, DL);
----------------
lukel97 wrote:

Can we use `VPInstruction::LastActiveLane` with the header mask, or an all ones mask if not tail folded? i think that would remove the need to extend the assert in fixupVFUsersForEVL

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


More information about the llvm-commits mailing list