OSDN Git Service

PR tree-optimization/41497
authorspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Oct 2009 23:05:39 +0000 (23:05 +0000)
committerspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Oct 2009 23:05:39 +0000 (23:05 +0000)
* tree-scalar-evolution.c (analyze_evolution_in_loop): Return
chrec_dont_know if the evolution function returned by follow_ssa_edge
is constant in the analyzed loop and is not compatible with the
initial value before the loop.
* tree-chrec.h (no_evolution_in_loop_p): Call STRIP_NOPS.

* gcc.dg/tree-ssa/pr41497.c: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153441 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr41497.c [new file with mode: 0644]
gcc/tree-chrec.h
gcc/tree-scalar-evolution.c

index cf2bc8f..d5e3ce9 100644 (file)
@@ -1,3 +1,12 @@
+2009-10-21  Sebastian Pop  <sebastian.pop@amd.com>
+
+       PR tree-optimization/41497
+       * tree-scalar-evolution.c (analyze_evolution_in_loop): Return
+       chrec_dont_know if the evolution function returned by follow_ssa_edge
+       is constant in the analyzed loop and is not compatible with the
+       initial value before the loop.
+       * tree-chrec.h (no_evolution_in_loop_p): Call STRIP_NOPS.
+
 2009-10-21  Joseph Myers  <joseph@codesourcery.com>
 
        * config/sh/sh.c (nonpic_symbol_mentioned_p): Allow UNSPEC_TPOFF.
index 75eb83d..d8b50b7 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-21  Sebastian Pop  <sebastian.pop@amd.com>
+
+       PR tree-optimization/41497
+       * gcc.dg/tree-ssa/pr41497.c: New.
+
 2009-10-21  Steve Ellcey  <sje@cup.hp.com>
 
        * g++.dg/tree-ssa/copyprop.C: Use include to define free().
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr41497.c b/gcc/testsuite/gcc.dg/tree-ssa/pr41497.c
new file mode 100644 (file)
index 0000000..e66ee84
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+
+extern void abort (void);
+
+unsigned int a;
+int b, c;
+
+void
+foo (void)
+{
+  b = 0;
+  do {
+    for (a = -13; a == 0; a = (unsigned short)a)
+      c = 1;
+    b++;
+  } while (b == 0);
+}
+
+int
+main ()
+{
+  foo ();
+  if (a != -13)
+    abort ();
+  return 0;
+}
index f21aa74..545db38 100644 (file)
@@ -115,6 +115,7 @@ no_evolution_in_loop_p (tree chrec, unsigned loop_num, bool *res)
       || chrec_contains_symbols_defined_in_loop (chrec, loop_num))
     return false;
 
+  STRIP_NOPS (chrec);
   scev = hide_evolution_in_other_loops_than_loop (chrec, loop_num);
   *res = !tree_is_chrec (scev);
   return true;
index 02a4eed..70af0fd 100644 (file)
@@ -1492,18 +1492,29 @@ analyze_evolution_in_loop (gimple loop_phi_node,
       bb = gimple_phi_arg_edge (loop_phi_node, i)->src;
       if (!flow_bb_inside_loop_p (loop, bb))
        continue;
-      
+
       if (TREE_CODE (arg) == SSA_NAME)
        {
+         bool val = false;
+
          ssa_chain = SSA_NAME_DEF_STMT (arg);
 
          /* Pass in the initial condition to the follow edge function.  */
          ev_fn = init_cond;
          res = follow_ssa_edge (loop, ssa_chain, loop_phi_node, &ev_fn, 0);
+
+         /* If ev_fn has no evolution in the inner loop, and the
+            init_cond is not equal to ev_fn, then we have an
+            ambiguity between two possible values, as we cannot know
+            the number of iterations at this point.  */
+         if (TREE_CODE (ev_fn) != POLYNOMIAL_CHREC
+             && no_evolution_in_loop_p (ev_fn, loop->num, &val) && val
+             && !operand_equal_p (init_cond, ev_fn, 0))
+           ev_fn = chrec_dont_know;
        }
       else
        res = t_false;
-             
+
       /* When it is impossible to go back on the same
         loop_phi_node by following the ssa edges, the
         evolution is represented by a peeled chrec, i.e. the