https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120141
Bug ID: 120141 Summary: [RVV] Noop are not removed Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: wojciech_mula at poczta dot onet.pl Target Milestone: --- I observed that RVV noops, like shifting by 0 or adding 0, are not removed from the program. I fully understand that a compiler cannot do it when `vsetvli` changes the mode between operations. But in the sample program `v8` is written and then shifted under the same vector mode. Is there any reason that comes from the RVV spec which is not obvious? Sample program: --- #include <riscv_vector.h> vuint16m1_t naive_avg(vuint16m1_t x, vuint16m1_t y) { const auto vl = __riscv_vsetvlmax_e16m1(); const auto a = __riscv_vadd(x, y, vl); return __riscv_vsrl(a, 0, vl); } --- Compiled with `-O3 -march=rv64gcv` yield the following assembly: --- naive_avg(__rvv_uint16m1_t, __rvv_uint16m1_t): vsetvli a5,zero,e16,m1,ta,ma vadd.vv v8,v8,v9 vsrl.vi v8,v8,0 ret ---