aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pop <sebastian.pop@amd.com>2009-10-21 23:05:39 +0000
committerSebastian Pop <sebastian.pop@amd.com>2009-10-21 23:05:39 +0000
commit6d64c143334282931dd29b4eb0402b5d571ab7ba (patch)
tree19f73c5acca1dc29d3476bc353efe3c387d3dae3
parent24a3db26e16d812b620bc768f99215959ce556e9 (diff)
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. * gcc.dg/tree-ssa/pr41497.c: New. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@153441 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr41497.c27
-rw-r--r--gcc/tree-chrec.h1
-rw-r--r--gcc/tree-scalar-evolution.c15
5 files changed, 55 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cf2bc8f3857..d5e3ce94a1f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 75eb83d76ee..d8b50b7b18d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 00000000000..e66ee846491
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr41497.c
@@ -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;
+}
diff --git a/gcc/tree-chrec.h b/gcc/tree-chrec.h
index f21aa74d795..545db38a730 100644
--- a/gcc/tree-chrec.h
+++ b/gcc/tree-chrec.h
@@ -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;
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index 02a4eed646e..70af0fda610 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -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