Paolo Bonzini wrote: > Hans-Peter Nilsson wrote: >>> Date: Fri, 5 Sep 2008 14:57:00 +0200 >>> From: Hans-Peter Nilsson <[EMAIL PROTECTED]> >>> Maybe as part of a change from target macro to target hook, with >>> LEGITIMATE_CONSTANT_P as a default would fit, even at this >>> stage? >> Sorry, I mean CONSTANT_P, not LEGITIMATE_CONSTANT_P. Or maybe a >> new macro or hook > > What about replacing the problematic uses of gen_rtx_CONST with > "plus_constant (x, 0)"? plus_constant knows when to make a CONST rtx. > > There are just a handful of places where this would be needed: instead > of the check after the wrong comment in cse.c, and everywhere > gen_rtx_CONST is used in simplify-rtx.c.
Here is a prototype patch, untested. Paolo
2008-09-06 Paolo Bonzini <[EMAIL PROTECTED]> * explow.c (plus_constant): Don't exit early if c == 0, to allow canonicalizing CONSTs. * cse.c (fold_rtx): Use plus_constant instead of wrapping with CONST. * simplify-rtx.c (simplify_plus_minus): Likewise. Index: cse.c =================================================================== --- cse.c (revision 134435) +++ cse.c (working copy) @@ -3161,10 +3161,8 @@ fold_rtx (rtx x, rtx insn) FIXME: those ports should be fixed. */ if (new != 0 && is_const && GET_CODE (new) == PLUS - && (GET_CODE (XEXP (new, 0)) == SYMBOL_REF - || GET_CODE (XEXP (new, 0)) == LABEL_REF) && GET_CODE (XEXP (new, 1)) == CONST_INT) - new = gen_rtx_CONST (mode, new); + new = plus_constant (XEXP (new, 0), XEXP (new, 1)); + else + new = plus_constant (new, 0); } break; Index: simplify-rtx.c =================================================================== --- simplify-rtx.c (revision 140055) +++ simplify-rtx.c (working copy) @@ -3625,7 +3625,7 @@ simplify_plus_minus (enum rtx_code code, tem = simplify_binary_operation (ncode, mode, tem_lhs, tem_rhs); if (tem && !CONSTANT_P (tem)) - tem = gen_rtx_CONST (GET_MODE (tem), tem); + tem = plus_constant (tem, 0); } else tem = simplify_binary_operation (ncode, mode, lhs, rhs); @@ -3690,7 +3690,7 @@ simplify_plus_minus (enum rtx_code code, && GET_CODE (ops[i].op) == GET_CODE (ops[i - 1].op)) { ops[i - 1].op = gen_rtx_MINUS (mode, ops[i - 1].op, ops[i].op); - ops[i - 1].op = gen_rtx_CONST (mode, ops[i - 1].op); + ops[i - 1].op = plus_constant (ops[i - 1].op, 0); if (i < n_ops - 1) ops[i] = ops[i + 1]; n_ops--; @@ -5247,7 +5247,7 @@ simplify_subreg (enum machine_mode outer && GET_MODE_BITSIZE (innermode) >= (2 * GET_MODE_BITSIZE (outermode)) && GET_CODE (XEXP (op, 1)) == CONST_INT && (INTVAL (XEXP (op, 1)) & (GET_MODE_BITSIZE (outermode) - 1)) == 0 - && INTVAL (XEXP (op, 1)) < GET_MODE_BITSIZE (innermode) + && INTVAL (XEXP (op, 1)) < GET_MODE_BITSIZE (innermode) && byte == subreg_lowpart_offset (outermode, innermode)) { int shifted_bytes = INTVAL (XEXP (op, 1)) / BITS_PER_UNIT; Index: explow.c =================================================================== --- explow.c (revision 134435) +++ explow.c (working copy) @@ -83,9 +83,6 @@ plus_constant (rtx x, HOST_WIDE_INT c) rtx tem; int all_constant = 0; - if (c == 0) - return x; - restart: code = GET_CODE (x);