https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108270
Bug ID: 108270
Summary: un-optimal vsetvl for multi-loop if avl is 0 ~ 31
immediate
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: juzhe.zhong at rivai dot ai
Target Milestone: ---
Consider this following case:
#include "riscv_vector.h"
void f1 (void * restrict in, void * restrict out, int l, int n, int m)
{
for (int i = 0; i < l; i++){
for (int j = 0; j < m; j++){
for (int k = 0; k < n; k++)
{
vint8mf8_t v = __riscv_vle8_v_i8mf8 (in + i + j, 17);
__riscv_vse8_v_i8mf8 (out + i + j, v, 17);
}
}
}
}
GCC ASM:
f1:
0: mv a7,a2
1: mv a6,a0
2: mv t1,a1
3: mv a2,a3
4: vsetivli zero,17,e8,mf8,ta,ma
5: ble a7,zero,.L1
6: ble a4,zero,.L1
7: ble a3,zero,.L1
8: add a1,a0,a4
9: li a0,0
10:.L4:
11: add a3,a6,a0
12: add a4,t1,a0
13:.L7:
14: li a5,0
15:.L5:
16: vle8.v v24,0(a3)
17: addiw a5,a5,1
18: vse8.v v24,0(a4)
19: bne a2,a5,.L5
20: addi a3,a3,1
21: addi a4,a4,1
22: bne a3,a1,.L7
23: addi a0,a0,1
24: addi a1,a1,1
25: bne a0,a7,.L4
26:.L1:
27: ret
The vsetivli instruction is hoisted too early. The best location of vsetivli
should be any point from 8 to 9.