]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Combine vec_duplicate + vwsubu.wv to vwsubu.wx on GR2VR cost
authorPan Li <pan2.li@intel.com>
Wed, 8 Oct 2025 14:12:38 +0000 (22:12 +0800)
committerPan Li <pan2.li@intel.com>
Fri, 10 Oct 2025 13:25:16 +0000 (21:25 +0800)
commit6c8bcbc10d6cec60ed616cfffd08d2357baa4735
tree35303c1e33c92e1dced5571f5518b346afc1b914
parent05e1cda2bd6ef370de19599d174c1146bd730ccf
RISC-V: Combine vec_duplicate + vwsubu.wv to vwsubu.wx on GR2VR cost

This patch would like to combine the vec_duplicate + vwsubu.wv to the
vwsubu.wx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

Assume we have asm code like below, GR2VR cost is 0.

Before this patch:
  11       beq a3,zero,.L8
  12       vsetvli a5,zero,e32,m1,ta,ma
  13       vmv.v.x v2,a2
  ...
  16   .L3:
  17       vsetvli a5,a3,e32,m1,ta,ma
  ...
  22       vwsubu.wv v1,v2,v3
  ...
  25       bne a3,zero,.L3

After this patch:
  11       beq a3,zero,.L8
  ...
  14    .L3:
  15       vsetvli a5,a3,e32,m1,ta,ma
  ...
  20       vwsubu.wx v1,a2,v3
  ...
  23       bne a3,zero,.L3

Unfortunately, and similar as vwaddu.vv, only widening from uint32_t to
uint64_t has the necessary zero-extend during combine, we loss the
extend op after expand for any other types.

gcc/ChangeLog:

* config/riscv/autovec-opt.md (*widen_wsubu_wx_<mode>): Add new
pattern to match vwsubu.wx.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/config/riscv/autovec-opt.md