diff options
author | Bernd Schmidt <bernd.schmidt@codesourcery.com> | 2010-03-19 18:41:22 +0000 |
---|---|---|
committer | Bernd Schmidt <bernds@gcc.gnu.org> | 2010-03-19 18:41:22 +0000 |
commit | c99102b8b4cc0ec725c741b13c6f406bbd924c73 (patch) | |
tree | 2bcf096e2c7a2d0589b6d0f349bfdd7ccaef90f5 /gcc | |
parent | 002b2dee5d23dff9cc0a7f3196838534bc084da4 (diff) | |
download | gcc-c99102b8b4cc0ec725c741b13c6f406bbd924c73.zip gcc-c99102b8b4cc0ec725c741b13c6f406bbd924c73.tar.gz gcc-c99102b8b4cc0ec725c741b13c6f406bbd924c73.tar.bz2 |
re PR target/40697 (inefficient code to extract least bits from an integer value)
gcc/
PR target/40697
* optabs.c (avoid_expensive_constant): Use rtx_cost to find out
the cost of loading the constant rather than assuming
COSTS_N_INSNS (1).
* config/arm/arm.c (thumb1_rtx_costs) <case CONST_INT>: If the
outer code is AND, do the same tests as the andsi3 expander and
return COSTS_N_INSNS (1) if and is cheap.
testsuite/
PR target/40697
* gcc.target/arm/thumb-andsi.c: New test.
From-SVN: r157582
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/config/arm/arm.c | 9 | ||||
-rw-r--r-- | gcc/optabs.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/arm/thumb-andsi.c | 10 |
5 files changed, 33 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bdc8dae..7afdbac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -4,6 +4,14 @@ * ira-lives.c (check_and_make_def_conflict): Ignore conflict for a use that may match DEF. + PR target/40697 + * optabs.c (avoid_expensive_constant): Use rtx_cost to find out + the cost of loading the constant rather than assuming + COSTS_N_INSNS (1). + * config/arm/arm.c (thumb1_rtx_costs) <case CONST_INT>: If the + outer code is AND, do the same tests as the andsi3 expander and + return COSTS_N_INSNS (1) if and is cheap. + 2010-03-19 Michael Matz <matz@suse.de> PR c++/43116 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 870e56e..cc023c1 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -6228,6 +6228,15 @@ thumb1_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) else if ((outer == IOR || outer == XOR || outer == AND) && INTVAL (x) < 256 && INTVAL (x) >= -256) return COSTS_N_INSNS (1); + else if (outer == AND) + { + int i; + /* This duplicates the tests in the andsi3 expander. */ + for (i = 9; i <= 31; i++) + if ((((HOST_WIDE_INT) 1) << i) - 1 == INTVAL (x) + || (((HOST_WIDE_INT) 1) << i) - 1 == ~INTVAL (x)) + return COSTS_N_INSNS (2); + } else if (outer == ASHIFT || outer == ASHIFTRT || outer == LSHIFTRT) return 0; diff --git a/gcc/optabs.c b/gcc/optabs.c index 747166b..a82619e 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -1389,11 +1389,11 @@ static rtx avoid_expensive_constant (enum machine_mode mode, optab binoptab, rtx x, bool unsignedp) { + bool speed = optimize_insn_for_speed_p (); if (mode != VOIDmode && optimize && CONSTANT_P (x) - && rtx_cost (x, binoptab->code, optimize_insn_for_speed_p ()) - > COSTS_N_INSNS (1)) + && rtx_cost (x, binoptab->code, speed) > rtx_cost (x, SET, speed)) { if (CONST_INT_P (x)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a13e712..6c7e19c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -2,7 +2,10 @@ PR rtl-optimization/42258 * gcc.target/arm/thumb1-mul-moves.c: New test. - + + PR target/40697 + * gcc.target/arm/thumb-andsi.c: New test. + 2010-03-19 Michael Matz <matz@suse.de> PR c++/43116 diff --git a/gcc/testsuite/gcc.target/arm/thumb-andsi.c b/gcc/testsuite/gcc.target/arm/thumb-andsi.c new file mode 100644 index 0000000..9e8e4d4 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/thumb-andsi.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -mthumb -march=armv5te" } */ + +unsigned get_least_bits(unsigned value) +{ + return value << 9 >> 9; +} + +/* { dg-final { scan-assembler "lsl" } } */ +/* { dg-final { scan-assembler "lsr" } } */ |