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: Checking out PR4483 (constant overflow on PPC, problems compiling Linux kernel)


David Edelsohn wrote:

>Corey> The bigger question is, though, should these even be getting into the 
>Corey> RTL?  Should this be handled here or is the bug in the optimizations 
>Corey> someplace?
>
>	This seems like you are solving the symptom of another problem.
>If the constant is not valid for the target, GCC should not be generating
>it to begin with.
>
You are right, of course.

I think I've fixed this correctly now (or at least pretty close), there 
were calculation being done that weren't properly truncating the 
integers.  IMHO, the root of the problem is that plus_constant() doesn't 
take a mode.  It seems to me that if you want to prevent this type of 
thing in the future, plus_constant() needs to be changed.  But that 
would be a big job; there are about 600 references
directly to plus_constant() in the source tree right now.

The change in recog.c was required because the first operand was a 
constant in this case, and it simplified it to a constant, but didn't 
have the mode to truncate it.  The change in simplify-rtx.c has to do 
with the fact that a unary minus can overflow if you have the maximum 
negative number.  I'm sure there are more of these, but this fixes the 
ones I saw (so far) compiling the Linux kernel.

-Corey

Index: recog.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/recog.c,v
retrieving revision 1.133
diff -u -p -r1.133 recog.c
--- recog.c	2001/11/02 10:52:08	1.133
+++ recog.c	2001/11/29 19:03:05
@@ -512,7 +512,8 @@ validate_replace_rtx_1 (loc, from, to, o
          separated from this function.  */
       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
 	validate_change (object, loc,
-			 plus_constant (XEXP (x, 0), INTVAL (XEXP (x, 1))), 1);
+			 simplify_gen_binary
+			 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
       break;
     case MINUS:
       if (GET_CODE (XEXP (x, 1)) == CONST_INT
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.86
diff -u -p -r1.86 simplify-rtx.c
--- simplify-rtx.c	2001/11/14 13:51:10	1.86
+++ simplify-rtx.c	2001/11/29 19:03:12
@@ -1276,7 +1276,8 @@ simplify_binary_operation (code, mode, o
 
 	  /* Don't let a relocatable value get a negative coeff.  */
 	  if (GET_CODE (op1) == CONST_INT && GET_MODE (op0) != VOIDmode)
-	    return plus_constant (op0, - INTVAL (op1));
+	    return plus_constant (op0,
+				  trunc_int_for_mode (- INTVAL (op1), mode));
 
 	  /* (x - (x & y)) -> (x & ~y) */
 	  if (GET_CODE (op1) == AND)

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