https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109399
Bug ID: 109399 Summary: RISC-V: RVV VSETVL PASS backward demand fusiton bug 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 foo(void *in1, void *in2, void *in3, void *out, size_t n) { size_t vl = __riscv_vsetvlmax_e32m1(); vint32m1_t a = __riscv_vle32_v_i32m1(in1, vl); vint32m1_t b = __riscv_vle32_v_i32m1_tu(a, in2, vl); vint32m1_t c = __riscv_vle32_v_i32m1_tu(b, in3, vl); __riscv_vse32_v_i32m1(out, c, vl); } Current codegen: foo: vsetvli a5,zero,e32,m1,ta,mu vle32.v v1,0(a0) vle32.v v1,0(a1) vle32.v v1,0(a2) vse32.v v1,0(a3) ret It's obvious that "ta,mu" is incorrect. Instead, we should emit vsetvl with "tu,m[au]" ,mask policy can be either mu or ma. But tail policy must be "tu". The reason we have this issue is that we didn't update && change user vsetvl instruction during local backward demand fusion (Phase 1). Will post a bug fix patch soon.