When building a const to a reg, it may need a few instructions. This patch updates rs6000_rtx_costs to make it more accurate for constant building.
With this patch, cse.cc could get accurate cost for complex constant and then read the constant from a pool. As discussed in the mail list, this patch is updating rtx_cost hook which may be preferred for this issue. Bootstrap and regtest pass on ppc64 and ppc64le. Is this ok for trunk or more suitable for stage1? BR, Jiufu PR target/63281 gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_rtx_costs): Update for const int. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr63281.c: New test. --- gcc/config/rs6000/rs6000.cc | 8 ++++++++ gcc/testsuite/gcc.target/powerpc/pr63281.c | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr63281.c diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 283e8306ff7..62fcd345af2 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -21838,6 +21838,14 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, case CONST_DOUBLE: case CONST_WIDE_INT: + /* Set a const to reg, it may needs a few insns. */ + if (outer_code == SET) + { + *total = COSTS_N_INSNS (num_insns_constant (x, mode)); + return true; + } + /* FALLTHRU */ + case CONST: case HIGH: case SYMBOL_REF: diff --git a/gcc/testsuite/gcc.target/powerpc/pr63281.c b/gcc/testsuite/gcc.target/powerpc/pr63281.c new file mode 100644 index 00000000000..469a8f64400 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr63281.c @@ -0,0 +1,11 @@ +/* PR target/63281 */ +/* { dg-do compile { target lp64 } } */ +/* { dg-options "-O2 -std=c99" } */ + +void +foo (unsigned long long *a) +{ + *a = 0x020805006106003; +} + +/* { dg-final { scan-assembler-times {\mp?ld\M} 1 } } */ -- 2.25.1