https://gcc.gnu.org/g:2da8c9ec0b06bf17fc5513ae22abafd0e1bdec18
commit r17-6578-g2da8c9ec0b06bf17fc5513ae22abafd0e1bdec18 Author: Jiahao Xu <[email protected]> Date: Sun Nov 8 11:09:41 2026 +0800 LoongArch: Add RTX costs for `if_then_else' expressions If there is no cost information from the backend, the middle end estimates the cost of if_then_else, which has three operands, as 3 instructions (i.e. 12 units). Define its cost as a single machine cycle, ignoring the cost of actually taking the branch, to enable more if-conversion optimizations. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_rtx_costs): <IF_THEN_ELSE>: New case. gcc/testsuite/ChangeLog: * gcc.target/loongarch/ifcvt-1.c: New test. Diff: --- gcc/config/loongarch/loongarch.cc | 4 ++++ gcc/testsuite/gcc.target/loongarch/ifcvt-1.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index db0c7516e60f..1b7f5b24c195 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -4153,6 +4153,10 @@ loongarch_rtx_costs (rtx x, machine_mode mode, int outer_code, switch (code) { + case IF_THEN_ELSE: + *total = COSTS_N_INSNS (1); + return true; + case CONST_INT: if (TARGET_64BIT && outer_code == AND && UINTVAL (x) == 0xffffffff) { diff --git a/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c b/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c new file mode 100644 index 000000000000..64a151a92f43 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "maskeqz" 2 } } */ +/* { dg-final { scan-assembler-times "masknez" 2 } } */ + +int +remove_one_fast (int *move_ordering, const int num_moves, int mark) +{ + int i, best = -1000000; + int tmp = 0; + + for (i = mark; i < num_moves; i++) + { + if (move_ordering[i] > best) + { + best = move_ordering[i]; + tmp = i; + } + } + + return tmp; +}
