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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 00:05:43 PDT 2025


================
@@ -917,6 +918,8 @@ Value *VPInstruction::generate(VPTransformState &State) {
 
     return Res;
   }
+  case VPInstruction::Reverse:
+    return Builder.CreateVectorReverse(State.get(getOperand(0)), "reverse");
----------------
lukel97 wrote:

> If a recipe isn’t converted to EVL form solely because it’s a VF user, then whether it carries VF as an operand seems irrelevant. 

Agreed, I think having a VF operand on reverse, vs. replacing the reverse with a vp.reverse intrinsic are both fine, this is somewhat separate from the header mask transform issue.

I think the most important thing is can't just find and replace any recipe that uses VF with EVL, and likewise we can't just replace all VPWidenLoadRecipes with EVL recipes either.

We need to specifically only replace these patterns which we know are correct to transform altogether, e.g:

```
   (load ptr, header-mask)
   ->
   (vp.load ptr, all-true, evl)
   
   (reverse (load (end-ptr p, vf), (reverse header-mask vf)), vf)
   ->
   (reverse (vp.load (end-ptr p, evl), all-true, evl), evl)
```

Or the reverse transform without a VF operand could also be:

```
   (reverse (load (end-ptr p, vf), (reverse header-mask)))
   ->
   (vp.reverse (vp.load (end-ptr p, evl), all-true, evl), evl)
```

I hope that makes sense. I'll post these comments in https://github.com/llvm/llvm-project/issues/152541 and move the discussion there.

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


More information about the llvm-commits mailing list