]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/42512 (integer wrong code bug with loop)
authorRichard Guenther <rguenther@suse.de>
Sat, 9 Jan 2010 12:04:17 +0000 (12:04 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Sat, 9 Jan 2010 12:04:17 +0000 (12:04 +0000)
2010-01-09  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.

From-SVN: r155757

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr42512.c [new file with mode: 0644]
gcc/tree-scalar-evolution.c

index 708dbf6803f18cf07599cf41d33ae6165fe4b810..99f59899bb6aea01bf6f487697c2409cbac4e512 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-09  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.
+
 2010-01-09  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c (process_command): Update copyright notice dates.
index fc9ee831db69099c4286537219e7f721009118bc..87d7a18c7e77dd2581e2b3d8add13eab7879682c 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-09  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/42512
+       * gcc.c-torture/execute/pr42512.c: New testcase.
+
 2010-01-09  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/41298
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr42512.c b/gcc/testsuite/gcc.c-torture/execute/pr42512.c
new file mode 100644 (file)
index 0000000..f4e5ced
--- /dev/null
@@ -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 087ba798830eebaea90946b53bf503ad1791c6ae..3ebc54e8556b02a0487e00b8f3740fcb65a5f597 100644 (file)
@@ -1642,6 +1642,23 @@ interpret_loop_phi (struct loop *loop, gimple loop_phi_node)
   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;
 }