[llvm] [RISCV] Combine build_vector of extract_vector_elts to vector_shuffle (PR #80883)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 18:51:41 PST 2024


lukel97 wrote:

> I was really only suggesting replacing the explode/build fallback with a packed shuffle fallback. 

To clarify, that's the only change I made.

> However if the source vector is > m1, then the vrgather is (in general) quadratic. Given the cost of the extract and insert will be either O(NumElems) for exact vlen or O(NumElems * LMUL) for default case, we have the possibility of introducing a regression here.

Indeed, I was hoping our shuffle lowering would have some sort of LMUL splitting strategy for this but it looks like we might only currently do it for the exact VLEN case.

As a side note, I noticed that we're extracting a v8i8 vector but we still set VL=64.

```
; CHECK-NEXT:    li a0, 64
; CHECK-NEXT:    vsetvli zero, a0, e8, m4, ta, ma
; CHECK-NEXT:    vid.v v12
; CHECK-NEXT:    vsll.vi v16, v12, 3
; CHECK-NEXT:    vrgather.vv v12, v8, v16
; CHECK-NEXT:    vmv1r.v v8, v12
; CHECK-NEXT:    ret
```

I think we can do this with VL=8 because as per the spec "The source vector can be read at any index < VLMAX regardless of vl."

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


More information about the llvm-commits mailing list