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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 7 05:51:06 PST 2026


================
@@ -2909,13 +2909,20 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
   VPValue *Addr, *Mask, *EndPtr;
 
   /// Adjust any end pointers so that they point to the end of EVL lanes not VF.
-  auto AdjustEndPtr = [&CurRecipe, &EVL](VPValue *EndPtr) {
-    auto *EVLEndPtr = cast<VPVectorEndPointerRecipe>(EndPtr)->clone();
-    EVLEndPtr->insertBefore(&CurRecipe);
-    EVLEndPtr->setOperand(1, &EVL);
-    return EVLEndPtr;
+  auto AdjustEndPtr = [&](VPValue *EndPtr) {
+    auto *VEPR = cast<VPVectorEndPointerRecipe>(EndPtr);
+    Type *SourceElementType = VEPR->getSourceElementType();
+    GEPNoWrapFlags NW = VEPR->getGEPNoWrapFlags();
+    VPBuilder Builder(&CurRecipe);
+    return Builder.createVectorEndPointerRecipe(VEPR->getOperand(0),
+                                                SourceElementType, -1, NW,
+                                                VEPR->getDebugLoc(), &EVL);
   };
 
+  auto MatchVecEndVF = m_c_Mul(
+      m_AllOnes(),
+      m_Sub(m_ZExtOrTruncOrSelf(m_Specific(&Plan->getVF())), m_SpecificInt(1)));
----------------
lukel97 wrote:

Can we fold the m_VecEndPtr part of the pattern into this too? Something like

```suggestion
  auto m_VecEndPtrVF = [&Plan](VPValue &Addr) {
     return m_VecEndPtr(m_VPValue(Addr), m_c_Mul(m_AllOnes(), m_Sub(m_ZExtOrTruncOrSelf(m_Specific(&Plan->getVF())), m_SpecificInt(1))));
   };
```

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


More information about the llvm-commits mailing list