]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Adjust widen-mul rtx cost
authorGuo Jie <guojie@loongson.cn>
Sat, 25 Oct 2025 02:43:36 +0000 (10:43 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 27 Oct 2025 09:52:34 +0000 (17:52 +0800)
commit48f624eb8dd19bc67cae59fd1dcada709d676154
tree899a70706dc9e5eef6533deda9855b871c0d3b8e
parent1b612139661e6c5ed9c727130d8d22e99b5512a1
LoongArch: Adjust widen-mul rtx cost

Equalize the rtx cost of mulw.d.w[u] with mul.d.

There are two main benefits:
1. Reducing the number of instructions.
    -       lu32i.d $r12,0
    -       bstrpick.d $r4,$r4,31,0
    -       mul.d $r4,$r4,$r12
    -       srli.d $r4,$r4,33
    ---
    +       mulh.wu $r4,$r4,$r12
    +       bstrpick.d $r4,$r4,31,1

2. Help with the replacement of the high-latency div.w.
    -       addi.w $r12,$r0,3
    -       div.w $r4,$r4,$r12
    ---
    +       lu12i.w $r13,349525
    +       ori $r13,$r13,1366
    +       mulw.d.w $r12,$r4,$r13
    +       srai.w  $r4,$r4,31
    +       srli.d $r12,$r12,32
    +       sub.w $r4,$r12,$r4

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_rtx_costs):
Ignore the cost impact of SIGN_EXTEND/ZERO_EXTEND.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/widen-mul-rtx-cost-signed.c: New test.
* gcc.target/loongarch/widen-mul-rtx-cost-unsigned.c: New test.
gcc/config/loongarch/loongarch.cc
gcc/testsuite/gcc.target/loongarch/widen-mul-rtx-cost-signed.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/widen-mul-rtx-cost-unsigned.c [new file with mode: 0644]