https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117947
Bug ID: 117947
Summary: [14/15 Regression] GCC miscompile rvv intrinsics at
`-O2` and `-O3`, use `vlenb` after an inappropriate
`vsetvli`
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: rvismith1115 at gmail dot com
Target Milestone: ---
Created attachment 59811
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59811&action=edit
reduced_testcase
code link: https://godbolt.org/z/zhToG9TfM
line 159-164, `a2` is set by `vlenb` in `e32m4`:
```
vsetvli zero,zero,e32,m4,ta,ma
vs8r.v v16,0(sp)
vmv.s.x v24,s4
vmv.s.x v16,t0
csrr a2,vlenb
vsetvli zero,zero,e16,m4,ta,ma
```
then, `a2` is used to update ptr in `e16m4`:
```
164: vsetvli zero,zero,e16,m4,ta,ma
183: vfmsub.vv v4,v4,v4
185: vsetvli zero,zero,e8,m2,ta,ma
196: vse16.v v4,0(a6)
197: add a6,a6,a2 (a bug occurred)
```
compile flag:
```
riscv64-unknown-elf-gcc -O3 -march=rv64gcv_zvfh -mabi=lp64d -Wno-psabi -static
```