]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/81555 (Wrong code at -O1)
authorJakub Jelinek <jakub@redhat.com>
Thu, 27 Jul 2017 09:43:01 +0000 (11:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 27 Jul 2017 09:43:01 +0000 (11:43 +0200)
PR tree-optimization/81555
PR tree-optimization/81556
* tree-ssa-reassoc.c (rewrite_expr_tree): Add NEXT_CHANGED argument,
if true, force CHANGED for the recursive invocation.
(reassociate_bb): Remember original length of ops array, pass
len != orig_len as NEXT_CHANGED in rewrite_expr_tree call.

* gcc.c-torture/execute/pr81555.c: New test.
* gcc.c-torture/execute/pr81556.c: New test.

From-SVN: r250616

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr81555.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr81556.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

index 65459ac278c58390ebd7af4e21506d2d1919f19f..0456556bb872b3b39be1731660b8fda9ee22dc9a 100644 (file)
@@ -1,3 +1,12 @@
+2017-07-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/81555
+       PR tree-optimization/81556
+       * tree-ssa-reassoc.c (rewrite_expr_tree): Add NEXT_CHANGED argument,
+       if true, force CHANGED for the recursive invocation.
+       (reassociate_bb): Remember original length of ops array, pass
+       len != orig_len as NEXT_CHANGED in rewrite_expr_tree call.
+
 2017-07-26  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline r235874
index 26a84ab89cb2fc5471d1b120cc1a313eace090fa..8e1d64be7d27c0817d8447529f17ccc45306d93c 100644 (file)
@@ -1,3 +1,10 @@
+2017-07-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/81555
+       PR tree-optimization/81556
+       * gcc.c-torture/execute/pr81555.c: New test.
+       * gcc.c-torture/execute/pr81556.c: New test.
+
 2016-07-25  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr81555.c b/gcc/testsuite/gcc.c-torture/execute/pr81555.c
new file mode 100644 (file)
index 0000000..d546368
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR tree-optimization/81555 */
+
+unsigned int a = 1, d = 0xfaeU, e = 0xe376U;
+_Bool b = 0, f = 1;
+unsigned char g = 1;
+
+void
+foo (void)
+{
+  _Bool c = a != b;
+  if (c)
+    f = 0;
+  if (e & c & (unsigned char)d & c)
+    g = 0;
+}
+
+int
+main ()
+{
+  foo ();
+  if (f || g != 1)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr81556.c b/gcc/testsuite/gcc.c-torture/execute/pr81556.c
new file mode 100644 (file)
index 0000000..cfbc75f
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/81556 */
+
+unsigned long long int b = 0xb82ff73c5c020599ULL;
+unsigned long long int c = 0xd4e8188733a29d8eULL;
+unsigned long long int d = 2, f = 1, g = 0, h = 0;
+unsigned long long int e = 0xf27771784749f32bULL;
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  _Bool a = d > 1;
+  g = f % ((d > 1) << 9);
+  h = a & (e & (a & b & c));
+}
+
+int
+main ()
+{
+  foo ();
+  if (g != 1 || h != 0)
+    __builtin_abort ();
+  return 0;
+}
index 29cfdee271ce4bc1c9c9cd691107ef10e53ad432..bdedf9d2cf3395788a5b496dbbe0c96a2ecf0c57 100644 (file)
@@ -3577,11 +3577,15 @@ find_insert_point (gimple stmt, tree rhs1, tree rhs2)
 
 /* Recursively rewrite our linearized statements so that the operators
    match those in OPS[OPINDEX], putting the computation in rank
-   order.  Return new lhs.  */
+   order.  Return new lhs.
+   CHANGED is true if we shouldn't reuse the lhs SSA_NAME both in
+   the current stmt and during recursive invocations.
+   NEXT_CHANGED is true if we shouldn't reuse the lhs SSA_NAME in
+   recursive invocations.  */
 
 static tree
 rewrite_expr_tree (gimple stmt, unsigned int opindex,
-                  vec<operand_entry_t> ops, bool changed)
+                  vec<operand_entry_t> ops, bool changed, bool next_changed)
 {
   tree rhs1 = gimple_assign_rhs1 (stmt);
   tree rhs2 = gimple_assign_rhs2 (stmt);
@@ -3660,7 +3664,8 @@ rewrite_expr_tree (gimple stmt, unsigned int opindex,
      be the non-leaf side.  */
   tree new_rhs1
     = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), opindex + 1, ops,
-                        changed || oe->op != rhs2);
+                        changed || oe->op != rhs2 || next_changed,
+                        false);
 
   if (oe->op != rhs2 || new_rhs1 != rhs1)
     {
@@ -4895,6 +4900,7 @@ reassociate_bb (basic_block bb)
              gimple_set_visited (stmt, true);
              linearize_expr_tree (&ops, stmt, true, true);
              ops.qsort (sort_by_operand_rank);
+             int orig_len = ops.length ();
              optimize_ops_list (rhs_code, &ops);
              if (undistribute_ops_list (rhs_code, &ops,
                                         loop_containing_stmt (stmt)))
@@ -4950,7 +4956,8 @@ reassociate_bb (basic_block bb)
                         swap_ops_for_binary_stmt (ops, len - 3, stmt);
 
                      new_lhs = rewrite_expr_tree (stmt, 0, ops,
-                                                  powi_result != NULL);
+                                                  powi_result != NULL,
+                                                  len != orig_len);
                     }
 
                  /* If we combined some repeated factors into a