Original patch:
http://gcc.gnu.org/ml/gcc-patches/2012-03/msg00208.html
'Tested' with..
../gcc-4_7-branch/configure --target=sh-elf --prefix=/usr/local
--enable-languages=c,c++ --enable-multilib --disable-libssp
--disable-nls --disable-werror --enable-lto --with-newlib --with-gnu-as
--with-gnu-ld --with-system-zlib
make all
OK for 4.7 branch?
ChangeLog:
Backport from mainline
2012-03-03 Kaz Kojima <[email protected]>
* config/sh/sh.c (shiftcosts): Return MAX_COST when the first
operand is CONST_INT. Take COSTS_N_INSNS into account.
(sh_rtx_costs): Don't apply COSTS_N_INSNS to the return value
of shiftcosts.
Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c (revision 188026)
+++ gcc/config/sh/sh.c (working copy)
@@ -2811,22 +2811,26 @@
{
int value;
+ /* There is no pattern for constant first operand. */
+ if (CONST_INT_P (XEXP (x, 0)))
+ return MAX_COST;
+
if (TARGET_SHMEDIA)
- return 1;
+ return COSTS_N_INSNS (1);
if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
{
if (GET_MODE (x) == DImode
&& CONST_INT_P (XEXP (x, 1))
&& INTVAL (XEXP (x, 1)) == 1)
- return 2;
+ return COSTS_N_INSNS (2);
/* Everything else is invalid, because there is no pattern for it. */
return MAX_COST;
}
/* If shift by a non constant, then this will be expensive. */
if (!CONST_INT_P (XEXP (x, 1)))
- return SH_DYNAMIC_SHIFT_COST;
+ return COSTS_N_INSNS (SH_DYNAMIC_SHIFT_COST);
/* Otherwise, return the true cost in instructions. Cope with out of range
shift counts more or less arbitrarily. */
@@ -2838,10 +2842,10 @@
/* If SH3, then we put the constant in a reg and use shad. */
if (cost > 1 + SH_DYNAMIC_SHIFT_COST)
cost = 1 + SH_DYNAMIC_SHIFT_COST;
- return cost;
+ return COSTS_N_INSNS (cost);
}
else
- return shift_insns[value];
+ return COSTS_N_INSNS (shift_insns[value]);
}
/* Return the cost of an AND/XOR/IOR operation. */
@@ -3074,7 +3078,7 @@
case ASHIFT:
case ASHIFTRT:
case LSHIFTRT:
- *total = COSTS_N_INSNS (shiftcosts (x));
+ *total = shiftcosts (x);
return true;
case DIV: