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: Fix PR 22018


On Wed, Jun 15, 2005 at 04:02:11PM +0200, Eric Botcazou wrote:

> I think you should add a comment explaining the dissymmetry in your code for 
> PLUS_EXPR and the dis-antisymmetry for MINUS_EXPR.  IMHO it's not trivial 
> to see that it is correct.
> 
Sure.


> Another strange thing is the dissymmetry MAX_EXPR/TYPE_MAX and 
> MIN_EXPR/TYPE_MIN: why do you need to test the sign for MAX_EXPR and not for 
> MIN_EXPR?
> 
Thanks for noticing.  I forgot to take it out before committing.
We don't even need to test MAX_EXPR there.  If neither VAL1 nor
VAL2 have overflowed, then it is impossible for the result to
overflow.


Diego.

	* tree-vrp.c (vrp_int_const_binop): Do not handle MAX_EXPR
	when the result overflows.


Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.28
diff -d -u -p -r2.28 tree-vrp.c
--- tree-vrp.c	15 Jun 2005 11:33:09 -0000	2.28
+++ tree-vrp.c	15 Jun 2005 14:21:59 -0000
@@ -996,9 +996,15 @@ vrp_int_const_binop (enum tree_code code
       int sgn1 = tree_int_cst_sgn (val1);
       int sgn2 = tree_int_cst_sgn (val2);
 
-      /* Notice that we only need to handle the restricted set of
-	 operations handled by extract_range_from_binary_expr.  */
-      if (((code == PLUS_EXPR || code == MAX_EXPR) && sgn2 >= 0)
+      /* Determine whether VAL1 CODE VAL2 yields a growing value.
+	 Notice that we only need to handle the restricted set of
+	 operations handled by extract_range_from_binary_expr:
+
+	 VAL1 + VAL2 grows if VAL2 is >= 0.
+	 VAL1 * VAL2 grows if both VAL1 and VAL2 have the same sign.
+	 VAL1 - VAL2 grows if VAL2 is < 0 (because it becomes an addition).
+      */
+      if ((code == PLUS_EXPR && sgn2 >= 0)
 	  || (code == MULT_EXPR && sgn1 == sgn2)
 	  || (code == MINUS_EXPR && sgn2 < 0))
 	grows = true;


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