https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113695

--- Comment #3 from Hao Du (杜浩) <hd701108 at gmail dot com> ---
Created attachment 66376
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66376&action=edit
vnsrl.wv testcase (preprocessed, trunk 20261201)

Two more instructions with this problem, still emitted by trunk
(gcc 17.0.0 20261201 (experimental) (crosstool-NG UNKNOWN), Compiler Explorer),
with
-O2 -march=rv64gcv -mabi=lp64d. Preprocessed testcases attached.

vnsrl.wv, where the shift amounts are the low half of the wide source:

  size_t vl = __riscv_vsetvl_e16m1 (n);
  vuint32m2_t w = __riscv_vle32_v_u32m2 (a, vl);
  vuint16m1_t sh = __riscv_vget_v_u16m2_u16m1
(__riscv_vreinterpret_v_u32m2_u16m2 (w), 0);
  __riscv_vse16_v_u16m1 (o, __riscv_vnsrl_wv_u16m1 (w, sh, vl), vl);

  ->  vnsrl.wv  v2,v2,v2

v2 is read as part of the EEW=32 group (vs2) and as the EEW=16 vs1.
vnsra.wv, vnclip.wv and vnclipu.wv behave the same.

vrgatherei16.vv, where the e16 indices are a view of the e32 data:

  vuint16m1_t ix = __riscv_vlmul_trunc_v_u16m2_u16m1
(__riscv_vreinterpret_v_u32m2_u16m2 (d));
  __riscv_vse32_v_u32m2 (o, __riscv_vrgatherei16_vv_u32m2 (d, ix, vl), vl);

  ->  vrgatherei16.vv  v4,v2,v2

We found these by rewriting the intrinsic calls in gcc.target/riscv/rvv so
that one vector operand becomes a vreinterpret/vlmul_trunc/vlmul_ext view
of another operand with a different element width. 77 such forms are still
emitted on trunk: besides the two above, vsoxei, and many cases where v0 is
read both as the mask and as a data source (for example
vadd.vv v1,v1,v0,v0.t and vmerge.vvm v2,v0,v1,v0). GCC 14.2 also did this
for vwadd/vwsub.wv, vfwadd/vfwsub.wv and the widening reductions; those are
clean on trunk.

LLVM has the same issue: https://github.com/llvm/llvm-project/issues/80099

Hao Du (杜浩, GitHub snozzz, [email protected])
Tong Liu (刘通, GitHub I3eg1nner, [email protected])

Reply via email to