[llvm] [VPlan] Directly unroll VectorEndPointerRecipe (PR #172372)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 00:14:25 PST 2026


================
@@ -313,6 +313,25 @@ void UnrollState::unrollRecipeByUF(VPRecipeBase &R) {
       Copy->addOperand(VFxPart);
       continue;
     }
+    if (auto *VEPR = dyn_cast<VPVectorEndPointerRecipe>(&R)) {
+      VPBuilder Builder(VEPR);
+      VPValue *PrevOffset =
+          cast<VPVectorEndPointerRecipe>(getValueForPart(VEPR, Part - 1))
+              ->getOffset();
+      Type *IndexTy = TypeInfo.inferScalarType(PrevOffset);
+      Type *VFTy = TypeInfo.inferScalarType(&Plan.getVF());
+      VPValue *VF = Builder.createScalarZExtOrTrunc(
+          &Plan.getVF(), IndexTy, VFTy, DebugLoc::getUnknown());
+      // Offset = PrevOffset + Stride * VF.
+      VPValue *VFxStride = Builder.createOverflowingOp(
+          Instruction::Mul, {VF, Plan.getConstantInt(IndexTy, VEPR->getStride(),
+                                                     /*IsSigned=*/true)});
+      VPValue *Offset = Builder.createOverflowingOp(Instruction::Add,
+                                                    {PrevOffset, VFxStride});
+      Copy->setOperand(0, VEPR->getOperand(0));
+      Copy->setOperand(1, Offset);
----------------
artagnon wrote:

The two are intertwined -- we build stuff ahead of time in createVEPR (at the Builder point) before calling the VPVectorEndPointerRecipe constructor, and this is necessary for correctness. I would have liked to move the additional construction into the VEPR constructor, but this is not possible, as we don't have access to the Plan.

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


More information about the llvm-commits mailing list