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]

[PATCH][4.1] Fix PR33142, wrong-code with VRP


This fixes PR33142, a case in VRP where we compared a value with the
types min/max value by pointer.  This doesn't work in some cases such
as mixed int/long types which don't share the constants even so they
have the same precision.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the
4.1 branch (and the testcase to 4.2 and trunk as well - some of Ians
patches fixed the issue there).

Richard.

2007-08-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/33142
	* tree-vrp.c (extract_range_from_unary_expr): Compare with
	TYPE_MIN/MAX_VALUE using tree_int_cst_equal.

	* gcc.c-torture/execute/pr33142.c: New testcase.

Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 127686)
--- tree-vrp.c	(working copy)
*************** extract_range_from_unary_expr (value_ran
*** 1523,1533 ****
  	  -~[MIN, MIN] == ~[MIN, MIN]
  	  -[MIN, 0] == [0, MAX]  for -fno-wrapv
  	  -[MIN, 0] == [0, MIN]  for -fwrapv (will be set to varying later)  */
!       min = vr0.max == TYPE_MIN_VALUE (TREE_TYPE (expr))
  	    ? TYPE_MIN_VALUE (TREE_TYPE (expr))
  	    : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max);
  
!       max = vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr))
  	    ? (vr0.type == VR_ANTI_RANGE || flag_wrapv
  	       ? TYPE_MIN_VALUE (TREE_TYPE (expr))
  	       : TYPE_MAX_VALUE (TREE_TYPE (expr)))
--- 1523,1533 ----
  	  -~[MIN, MIN] == ~[MIN, MIN]
  	  -[MIN, 0] == [0, MAX]  for -fno-wrapv
  	  -[MIN, 0] == [0, MIN]  for -fwrapv (will be set to varying later)  */
!       min = tree_int_cst_equal (vr0.max, TYPE_MIN_VALUE (TREE_TYPE (expr)))
  	    ? TYPE_MIN_VALUE (TREE_TYPE (expr))
  	    : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max);
  
!       max = tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr)))
  	    ? (vr0.type == VR_ANTI_RANGE || flag_wrapv
  	       ? TYPE_MIN_VALUE (TREE_TYPE (expr))
  	       : TYPE_MAX_VALUE (TREE_TYPE (expr)))
*************** extract_range_from_unary_expr (value_ran
*** 1540,1548 ****
           useful range.  */
        if (flag_wrapv
  	  && ((vr0.type == VR_RANGE
! 	       && vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr)))
  	      || (vr0.type == VR_ANTI_RANGE
! 	          && vr0.min != TYPE_MIN_VALUE (TREE_TYPE (expr))
  		  && !range_includes_zero_p (&vr0))))
  	{
  	  set_value_range_to_varying (vr);
--- 1540,1548 ----
           useful range.  */
        if (flag_wrapv
  	  && ((vr0.type == VR_RANGE
! 	       && tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr))))
  	      || (vr0.type == VR_ANTI_RANGE
! 	          && !tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr)))
  		  && !range_includes_zero_p (&vr0))))
  	{
  	  set_value_range_to_varying (vr);
*************** extract_range_from_unary_expr (value_ran
*** 1551,1557 ****
  	
        /* ABS_EXPR may flip the range around, if the original range
  	 included negative values.  */
!       min = (vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr)))
  	    ? TYPE_MAX_VALUE (TREE_TYPE (expr))
  	    : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min);
  
--- 1551,1557 ----
  	
        /* ABS_EXPR may flip the range around, if the original range
  	 included negative values.  */
!       min = (tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr))))
  	    ? TYPE_MAX_VALUE (TREE_TYPE (expr))
  	    : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min);
  
*************** extract_range_from_unary_expr (value_ran
*** 1575,1581 ****
  	         or ~[-INF + 1, min (abs(MIN), abs(MAX))] when
  		 flag_wrapv is set and the original anti-range doesn't include
  	         TYPE_MIN_VALUE, remember -TYPE_MIN_VALUE = TYPE_MIN_VALUE.  */
! 	      min = (flag_wrapv && vr0.min != type_min_value
  		     ? int_const_binop (PLUS_EXPR,
  					type_min_value,
  					integer_one_node, 0)
--- 1575,1581 ----
  	         or ~[-INF + 1, min (abs(MIN), abs(MAX))] when
  		 flag_wrapv is set and the original anti-range doesn't include
  	         TYPE_MIN_VALUE, remember -TYPE_MIN_VALUE = TYPE_MIN_VALUE.  */
! 	      min = (flag_wrapv && !tree_int_cst_equal (vr0.min, type_min_value)
  		     ? int_const_binop (PLUS_EXPR,
  					type_min_value,
  					integer_one_node, 0)
Index: testsuite/gcc.c-torture/execute/pr33142.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr33142.c	(revision 0)
--- testsuite/gcc.c-torture/execute/pr33142.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ int abs(int j);
+ extern void abort(void);
+ 
+ __attribute__((noinline)) int lisp_atan2(long dy, long dx) {
+     if (dx <= 0)
+         if (dy > 0)
+             return abs(dx) <= abs(dy);
+     return 0;
+ }
+ 
+ int main() {   
+     volatile long dy = 63, dx = -77;
+     if (lisp_atan2(dy, dx))
+         abort();
+     return 0;
+ }


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