This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch: CSE bug when narrowing constants
- From: Gary Funck <gary at intrepid dot com>
- To: Gcc Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 28 Nov 2008 17:26:25 -0800
- Subject: patch: CSE bug when narrowing constants
Although this bug hasn't been confirmed yet:
http://gcc.gnu.org/ml/gcc/2008-11/msg00360.html
this patch fixes the problem:
Index: cse.c
===================================================================
RCS file: /eng/cvs/pub/upc/gcc-upc-4-2/gcc/cse.c,v
retrieving revision 1.1.1.4
diff -u -p -r1.1.1.4 cse.c
--- cse.c 22 Apr 2008 16:34:51 -0000 1.1.1.4
+++ cse.c 29 Nov 2008 01:18:13 -0000
@@ -1452,6 +1452,8 @@ lookup_as_function (rtx x, enum rtx_code
static rtx
lookup_as_function (rtx x, enum rtx_code code)
{
+ int narrowing = 0;
+ enum machine_mode mode = GET_MODE (x);
struct table_elt *p
= lookup (x, SAFE_HASH (x, VOIDmode), GET_MODE (x));
@@ -1459,8 +1461,9 @@ lookup_as_function (rtx x, enum rtx_code
long as we are narrowing. So if we looked in vain for a mode narrower
than word_mode before, look for word_mode now. */
if (p == 0 && code == CONST_INT
- && GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (word_mode))
+ && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
{
+ narrowing = 1;
x = copy_rtx (x);
PUT_MODE (x, word_mode);
p = lookup (x, SAFE_HASH (x, VOIDmode), word_mode);
@@ -1473,7 +1476,12 @@ lookup_as_function (rtx x, enum rtx_code
if (GET_CODE (p->exp) == code
/* Make sure this is a valid entry in the table. */
&& exp_equiv_p (p->exp, p->exp, 1, false))
- return p->exp;
+ {
+ rtx result = p->exp;
+ if (narrowing)
+ result = gen_lowpart (mode, result);
+ return result;
+ }
return 0;
}