]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Optimize AND large immediate operation
authorGuo Jie <guojie@loongson.cn>
Sun, 2 Nov 2025 03:30:57 +0000 (11:30 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 3 Nov 2025 08:09:29 +0000 (16:09 +0800)
commit2ae8cb4201c2e1f7bd0d03a5ffe4fcc371ddc882
tree123d8e20132dd0713d50027abd8f5cb50ef4628c
parentfbd9051a96a3a2e7ee7db5524e79e42c6477ef65
LoongArch: Optimize AND large immediate operation

For large immediate values in variable AND operations:
if their bit representation has two consecutive 0 sequences,
one starting from the MSB can use the bstrpick.d instruction,
and the bstrins.d instruction for the other.

For example, in the case 'var & 0x3fffffffefffffff':

Before:
    lu12i.w $r12,-65537
    ori     $r12,$r12,4095
    lu52i.d $r12,$r12,0x3ff
    and     $r4,$r4,$r12

After:
    bstrpick.d $r4,$r4,61,0
    bstrins.d $r4,$r0,28,28

gcc/ChangeLog:

* config/loongarch/loongarch-protos.h
(loongarch_use_bstrins_bstrpick_for_and): New proto.
* config/loongarch/loongarch.cc
(loongarch_use_bstrins_bstrpick_for_and): Decide whether
to optimize.
(loongarch_rtx_costs): Adjust the cost of AND operation.
* config/loongarch/loongarch.md
(bstrins_bstrpick_for_and_imm<mode>): New insn_and_split.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/and-large-immediate-opt.c: New test.
gcc/config/loongarch/loongarch-protos.h
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.md
gcc/testsuite/gcc.target/loongarch/and-large-immediate-opt.c [new file with mode: 0644]