[llvm] [VPlan] Extract reverse operation for reverse accesses (PR #146525)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 15 03:13:15 PDT 2025


================
@@ -2482,6 +2482,29 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
       .Case<VPWidenStoreRecipe>([&](VPWidenStoreRecipe *S) {
         VPValue *NewMask = GetNewMask(S->getMask());
         VPValue *NewAddr = GetNewAddr(S->getAddr());
+        // Convert general reverse operations on stored value into vp.reverse,
+        // when the VPVectorEndPointerRecipe adjusting the access address uses
+        // EVL instead of VF.
+        if (match(NewAddr, m_VectorEndPointer(m_VPValue(), m_Specific(&EVL)))) {
+          VPValue *StoredVal = S->getStoredValue();
+          // Skip if the stored value is not defined in the loop region.
+          if (!StoredVal->isDefinedOutsideLoopRegions()) {
----------------
Mel-Chen wrote:

I used to worry about the same issue. Since vp.reverse requires EVL as its operand, a reverse defined in the per-header cannot be converted into vp.reverse unless we sink the reverse back into the vectorized loop. But I can’t imagine of a situation where, inside the vectorized loop, we would store a vector defined in the perheader with different values in each lane.

Do you think we should be conservative and first sink the reverse defined in the perheader back into the vectorized loop body and convert it into vp.reverse, or is it reasonable to add an assertion here to ensure that, if all of stored value lanes are identical?

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


More information about the llvm-commits mailing list