]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Optimize additions with immediates
authorXi Ruoyao <xry111@xry111.site>
Sun, 2 Apr 2023 13:37:49 +0000 (21:37 +0800)
committerXi Ruoyao <xry111@xry111.site>
Tue, 18 Apr 2023 06:37:10 +0000 (14:37 +0800)
commit603fc926fee69ab3c7169af8a9c0918611a75d92
tree4d5eb8c67cb21a5522a8cc3f130b3961fae0014a
parente722a1f42b28092c9f709a3f758fc4fe57db32b0
LoongArch: Optimize additions with immediates

1. Use addu16i.d for TARGET_64BIT and suitable immediates.
2. Split one addition with immediate into two addu16i.d or addi.{d/w}
   instructions if possible.  This can avoid using a temp register w/o
   increase the count of instructions.

Inspired by https://reviews.llvm.org/D143710 and
https://reviews.llvm.org/D147222.

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for GCC 14?

gcc/ChangeLog:

* config/loongarch/loongarch-protos.h
(loongarch_addu16i_imm12_operand_p): New function prototype.
(loongarch_split_plus_constant): Likewise.
* config/loongarch/loongarch.cc
(loongarch_addu16i_imm12_operand_p): New function.
(loongarch_split_plus_constant): Likewise.
* config/loongarch/loongarch.h (ADDU16I_OPERAND): New macro.
(DUAL_IMM12_OPERAND): Likewise.
(DUAL_ADDU16I_OPERAND): Likewise.
* config/loongarch/constraints.md (La, Lb, Lc, Ld, Le): New
constraint.
* config/loongarch/predicates.md (const_dual_imm12_operand): New
predicate.
(const_addu16i_operand): Likewise.
(const_addu16i_imm12_di_operand): Likewise.
(const_addu16i_imm12_si_operand): Likewise.
(plus_di_operand): Likewise.
(plus_si_operand): Likewise.
(plus_si_extend_operand): Likewise.
* config/loongarch/loongarch.md (add<mode>3): Convert to
define_insn_and_split.  Use plus_<mode>_operand predicate
instead of arith_operand.  Add alternatives for La, Lb, Lc, Ld,
and Le constraints.
(*addsi3_extended): Convert to define_insn_and_split.  Use
plus_si_extend_operand instead of arith_operand.  Add
alternatives for La and Le alternatives.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/add-const.c: New test.
* gcc.target/loongarch/stack-check-cfa-1.c: Adjust for stack
frame size change.
* gcc.target/loongarch/stack-check-cfa-2.c: Likewise.
gcc/config/loongarch/constraints.md
gcc/config/loongarch/loongarch-protos.h
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.h
gcc/config/loongarch/loongarch.md
gcc/config/loongarch/predicates.md
gcc/testsuite/gcc.target/loongarch/add-const.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c