[PATCH][4.1] Fix PR27603

Richard Guenther rguenther@suse.de
Mon May 15 15:53:00 GMT 2006


This patch fixes PR27603, a wrong-code bug due to wrong information from
infer_loop_bounds_from_undefined in VRP.

Bootstrapped and tested on the 4.1 branch on x86_64-unknown-linux-gnu.

Ok for 4.1?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-05-15  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/27603
	* tree-ssa-loop-niter.c (infer_loop_bounds_from_undefined):
	Do computation in original type, do division only for nonzero
	steps.

	* gcc.dg/torture/pr27603.c: New testcase.

Index: tree-ssa-loop-niter.c
===================================================================
*** tree-ssa-loop-niter.c	(revision 113782)
--- tree-ssa-loop-niter.c	(working copy)
*************** infer_loop_bounds_from_undefined (struct
*** 1562,1576 ****
  
  		    utype = unsigned_type_for (type);
  		    if (tree_int_cst_lt (step, integer_zero_node))
! 		      diff = fold_build2 (MINUS_EXPR, utype, init,
  					  TYPE_MIN_VALUE (type));
  		    else
! 		      diff = fold_build2 (MINUS_EXPR, utype,
  					  TYPE_MAX_VALUE (type), init);
  
! 		    estimation = fold_build2 (CEIL_DIV_EXPR, utype, diff,
! 					      step);
! 		    record_estimate (loop, estimation, boolean_true_node, stmt);
  		  }
  
  		break;
--- 1562,1581 ----
  
  		    utype = unsigned_type_for (type);
  		    if (tree_int_cst_lt (step, integer_zero_node))
! 		      diff = fold_build2 (MINUS_EXPR, type, init,
  					  TYPE_MIN_VALUE (type));
  		    else
! 		      diff = fold_build2 (MINUS_EXPR, type,
  					  TYPE_MAX_VALUE (type), init);
  
! 		    if (integer_nonzerop (step))
! 		      {
! 			estimation = fold_build2 (CEIL_DIV_EXPR, type, diff,
! 						  step);
! 			record_estimate (loop,
! 					 fold_convert (utype, estimation),
! 					 boolean_true_node, stmt);
! 		      }
  		  }
  
  		break;
Index: testsuite/gcc.dg/torture/pr27603.c
===================================================================
*** testsuite/gcc.dg/torture/pr27603.c	(revision 0)
--- testsuite/gcc.dg/torture/pr27603.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do run } */
+ 
+ void exit (int);
+ void abort (void);
+ int a;
+ int main()
+ {
+   int j;
+   for (j = 0; j < 6; j++)
+   {
+     if ((unsigned)j - 3 <= 1)
+       exit (0);
+     a = 1000 * (6 - j);
+   }
+   abort ();
+ }



More information about the Gcc-patches mailing list