https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113697
Bug ID: 113697
Summary: RISC-V: Redundant vsetvl insn in function
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pan2.li at intel dot com
Target Milestone: ---
Give the sample code as below, build with -march=rv64gcv -O3 -g0
int foo (int * __restrict a, int n)
{
int result = 0;
for (int i = 0; i < n; i++)
result += a[i];
return result;
}
The asm code looks like below, we have one duplicated vsetvl insn here.
foo:
.LFB0:
.cfi_startproc
ble a1,zero,.L4
vsetvli a5,zero,e32,m1,ta,ma
vmv.v.i v1,0
.L3:
vsetvli a5,a1,e32,m1,tu,ma
slli a4,a5,2
sub a1,a1,a5
vle32.v v2,0(a0)
add a0,a0,a4
vadd.vv v1,v2,v1
bne a1,zero,.L3
li a5,0
vsetivli zero,1,e32,m1,ta,ma
vmv.s.x v2,a5
vsetvli a5,zero,e32,m1,ta,ma <== redundant vsetvl
vredsum.vs v1,v1,v2
vmv.x.s a0,v1
ret
.L4:
li a0,0
ret