re PR tree-optimization/41497 (apparent integer wrong code bug)

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.

From-SVN: r153441
This commit is contained in:
Sebastian Pop 2009-10-21 23:05:39 +00:00 committed by Sebastian Pop
parent f4e1881041
commit f29deac9bd
5 changed files with 55 additions and 2 deletions

View 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.

View 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().

View File

@ -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;
}

View 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;

View 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