This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: patch to stop GCC from shifting by a negative number


Steve Ellcey <sje@cup.hp.com> writes:

> I tracked down a difference between a cross-compiling GCC and a native
> built GCC to trunc_int_for_mode trying to shift by a negative number
> when the function is getting called by general_operand with a CONST_INT
> rtx and a mode of VOIDmode.

Ugh.  It really shouldn't be called this way; it makes no sense.

In fact, in const_int_operand, there's a guard around the
trunc_int_for_mode call to check it against VOIDmode.

What do you think about a patch like this (very lightly tested)?

2002-08-12  Geoffrey Keating  <geoffk@redhat.com>

	* explow.c (trunc_int_for_mode): Abort when the mode is not
	an integer mode.
	* combine.c (simplify_comparison): Don't call trunc_int_for_mode
	for VOIDmode.
	* recog.c (general_operand): Likewise.
	(immediate_operand): Likewise.
	(nonmemory_operand): Likewise.

Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.309
diff -p -u -p -r1.309 combine.c
--- combine.c	1 Aug 2002 09:08:38 -0000	1.309
+++ combine.c	12 Aug 2002 23:52:14 -0000
@@ -10177,7 +10177,9 @@ simplify_comparison (code, pop0, pop1)
 
       /* Get the constant we are comparing against and turn off all bits
 	 not on in our mode.  */
-      const_op = trunc_int_for_mode (INTVAL (op1), mode);
+      const_op = INTVAL (op1);
+      if (mode != VOIDmode)
+	const_op = trunc_int_for_mode (const_op, mode);
       op1 = GEN_INT (const_op);
 
       /* If we are comparing against a constant power of two and the value
Index: explow.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/explow.c,v
retrieving revision 1.99
diff -p -u -p -r1.99 explow.c
--- explow.c	3 Aug 2002 20:20:35 -0000	1.99
+++ explow.c	12 Aug 2002 23:52:15 -0000
@@ -49,6 +49,11 @@ trunc_int_for_mode (c, mode)
 {
   int width = GET_MODE_BITSIZE (mode);
 
+  /* You want to truncate to a _what_?  */
+  if (GET_MODE_CLASS (mode) != MODE_INT
+      && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
+    abort ();
+
   /* Canonicalize BImode to 0 and STORE_FLAG_VALUE.  */
   if (mode == BImode)
     return c & 1 ? STORE_FLAG_VALUE : 0;
Index: recog.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/recog.c,v
retrieving revision 1.162
diff -p -u -p -r1.162 recog.c
--- recog.c	23 Jul 2002 20:50:59 -0000	1.162
+++ recog.c	12 Aug 2002 23:52:15 -0000
@@ -954,6 +954,7 @@ general_operand (op, mode)
     return 0;
 
   if (GET_CODE (op) == CONST_INT
+      && mode != VOIDmode
       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
     return 0;
 
@@ -1159,6 +1160,7 @@ immediate_operand (op, mode)
     return 0;
 
   if (GET_CODE (op) == CONST_INT
+      && mode != VOIDmode
       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
     return 0;
 
@@ -1241,6 +1243,7 @@ nonmemory_operand (op, mode)
 	return 0;
 
       if (GET_CODE (op) == CONST_INT
+	  && mode != VOIDmode
 	  && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
 	return 0;
 
-- 
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]