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

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 7 01:15:54 PDT 2025


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

I’m proposing two possible directions, both of which are implementable.

The first approach, https://github.com/Mel-Chen/llvm-project/commit/bc338ad5bd9de3889e263c3910e6908c7b9533a0, as suggested by @lukel97 , defines all reverse operations as:
```
res = reverse op, N
```
With the semantics:
```
res[i] = op[N - 1 - i], for 0 <= i < N  
res[i] = op[i],         for i >= N
```
Initially, N is set to VF, and during EVL lowering, it will be replaced with EVL.

The second approach, https://github.com/Mel-Chen/llvm-project/commit/132f84dc7e042c8084af28cba1b99d2066faaa59, defines the reverse operation as:
```
res = reverse op
```
With the semantics:
```
res[i] = op[VF - 1 - i], for 0 <= i < VF
```
During EVL lowering, VF is treated similarly to a header mask. If needed, we recursively convert users into EVL recipes (e.g., vp.splice, vp.reverse). We can move the functionality of `convertToEVLReverse` into `convertToEVLRecipe`, achieving the design suggested by @fhahn in https://github.com/llvm/llvm-project/pull/146525#discussion_r2244866257.

I’d like to know everyone’s preferences so we can move forward with this.

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


More information about the llvm-commits mailing list