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] Fix PR 27136


This fixes PR27136 by punting earlier in trying to brute-forcing
the number of iterations of a loop instead of folding a self-referencing
tree.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.

Ok for mainline and 4.1, 4.0 after a while?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-04-17  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/27136
	* tree-ssa-loop-niter.c (get_val_for): Correct function
	comment, assert requirements.
	(loop_niter_by_eval): Stop processing if the iterated
	value did not simplify.

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

Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 113003)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** get_base_for (struct loop *loop, tree x)
*** 1226,1232 ****
  
  /* Given an expression X, then 
   
!    * if BASE is NULL_TREE, X must be a constant and we return X.
     * otherwise X is a SSA name, whose value in the considered loop is derived
       by a chain of operations with constant from a result of a phi node in
       the header of the loop.  Then we return value of X when the value of the
--- 1226,1232 ----
  
  /* Given an expression X, then 
   
!    * if X is NULL_TREE, we return the constant BASE.
     * otherwise X is a SSA name, whose value in the considered loop is derived
       by a chain of operations with constant from a result of a phi node in
       the header of the loop.  Then we return value of X when the value of the
*************** get_val_for (tree x, tree base)
*** 1239,1244 ****
--- 1239,1246 ----
    use_operand_p op;
    ssa_op_iter iter;
  
+   gcc_assert (is_gimple_min_invariant (base));
+ 
    if (!x)
      return base;
  
*************** loop_niter_by_eval (struct loop *loop, e
*** 1339,1345 ****
  	}
  
        for (j = 0; j < 2; j++)
! 	val[j] = get_val_for (next[j], val[j]);
      }
  
    return chrec_dont_know;
--- 1341,1351 ----
  	}
  
        for (j = 0; j < 2; j++)
! 	{
! 	  val[j] = get_val_for (next[j], val[j]);
! 	  if (!is_gimple_min_invariant (val[j]))
! 	    return chrec_dont_know;
! 	}
      }
  
    return chrec_dont_know;
Index: gcc/testsuite/gcc.dg/torture/pr27136.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr27136.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr27136.c	(revision 0)
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile } */
+ /* { dg-options "-ffast-math" } */
+ 
+ void foo()
+ {
+   double x;
+ 
+   for (x = 2; x < 10; x *= x)
+     ;
+ }


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