This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR42512
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: spop at gcc dot gnu dot org
- Date: Fri, 8 Jan 2010 20:20:07 +0100 (CET)
- Subject: [PATCH] Fix PR42512
This fixes PR42512 where we compute invalid evolutions as
shown in the bugzilla audit trail.
Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk?
Thanks,
Richard.
2010-01-08 Richard Guenther <rguenther@suse.de>
PR middle-end/42512
* tree-scalar-evolution.c (interpret_loop_phi): Make sure
the evolution is compatible with the initial condition.
* gcc.c-torture/execute/pr42512.c: New testcase.
Index: gcc/testsuite/gcc.c-torture/execute/pr42512.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr42512.c (revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr42512.c (revision 0)
***************
*** 0 ****
--- 1,13 ----
+ extern void abort (void);
+
+ short g_3;
+
+ int main (void)
+ {
+ int l_2;
+ for (l_2 = -1; l_2 != 0; l_2 = (unsigned char)(l_2 - 1))
+ g_3 |= l_2;
+ if (g_3 != -1)
+ abort ();
+ return 0;
+ }
Index: gcc/tree-scalar-evolution.c
===================================================================
*** gcc/tree-scalar-evolution.c (revision 155739)
--- gcc/tree-scalar-evolution.c (working copy)
*************** interpret_loop_phi (struct loop *loop, g
*** 1642,1647 ****
--- 1642,1664 ----
init_cond = analyze_initial_condition (loop_phi_node);
res = analyze_evolution_in_loop (loop_phi_node, init_cond);
+ /* Verify we maintained the correct initial condition throughout
+ possible conversions in the SSA chain. */
+ if (res != chrec_dont_know)
+ {
+ tree new_init = res;
+ if (CONVERT_EXPR_P (res)
+ && TREE_CODE (TREE_OPERAND (res, 0)) == POLYNOMIAL_CHREC)
+ new_init = fold_convert (TREE_TYPE (res),
+ CHREC_LEFT (TREE_OPERAND (res, 0)));
+ else if (TREE_CODE (res) == POLYNOMIAL_CHREC)
+ new_init = CHREC_LEFT (res);
+ STRIP_USELESS_TYPE_CONVERSION (new_init);
+ gcc_assert (TREE_CODE (new_init) != POLYNOMIAL_CHREC);
+ if (!operand_equal_p (init_cond, new_init, 0))
+ return chrec_dont_know;
+ }
+
return res;
}