re PR tree-optimization/77454 (IMM ERROR w/ -O2 and above)
authorJakub Jelinek <jakub@redhat.com>
Tue, 13 Sep 2016 19:19:33 +0000 (21:19 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 13 Sep 2016 19:19:33 +0000 (21:19 +0200)
PR tree-optimization/77454
* tree-ssa-dom.c (optimize_stmt): Set modified flag on stmt after
changing GIMPLE_COND.  Move update_stmt_if_modified call after this.
Formatting fix.

* gcc.dg/pr77454.c: New test.

From-SVN: r240120

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr77454.c [new file with mode: 0644]
gcc/tree-ssa-dom.c

index d54fc605798d19144b889b3eaf5da73e74d5b22b..82034a9a8b73ef7237683c41d5dee0c04d2ebe39 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/77454
+       * tree-ssa-dom.c (optimize_stmt): Set modified flag on stmt after
+       changing GIMPLE_COND.  Move update_stmt_if_modified call after this.
+       Formatting fix.
+
 2016-09-13  Tamar Christina  <tamar.christina@arm.com>
 
        * config/aarch64/aarch64-builtins.c 
index 64ce0ce8e6f57d6a03a09fec63ed63e88de984f6..a89273701919c91514a714fc4002b6f30775e94c 100644 (file)
@@ -1,5 +1,8 @@
 2016-09-13  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/77454
+       * gcc.dg/pr77454.c: New test.
+
        PR c++/77553
        * g++.dg/cpp1y/constexpr-77553.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr77454.c b/gcc/testsuite/gcc.dg/pr77454.c
new file mode 100644 (file)
index 0000000..1bb41c2
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR tree-optimization/77454 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void
+foo (unsigned char x, char y)
+{
+  while (x != 0)
+    {
+      unsigned char *a = &x;
+      int b;
+
+      if (y != 0)
+       a = (unsigned char *) &y;
+      else if (y + 1 != 0)
+       a = (unsigned char *) &y;
+      for (x = 0; x < 1; ++x)
+       b = 0;
+      for (y = 0; y < 3; ++y)
+       {
+         y = !!y;
+         if (y != 0)
+           x = y;
+       }
+      if ((b != 0 ? -1 : *a) < (y = b))
+       b = 1;
+    }
+}
index 8bf5b3c9ffed19d19850c31482a9c38f1fd6f0f8..b007388f3eacd07a9d660e0c23a47828fa91bc7a 100644 (file)
@@ -1923,12 +1923,11 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si,
     {
       tree val = NULL;
 
-      update_stmt_if_modified (stmt);
-
       if (gimple_code (stmt) == GIMPLE_COND)
         val = fold_binary_loc (gimple_location (stmt),
-                          gimple_cond_code (stmt), boolean_type_node,
-                           gimple_cond_lhs (stmt),  gimple_cond_rhs (stmt));
+                              gimple_cond_code (stmt), boolean_type_node,
+                              gimple_cond_lhs (stmt),
+                              gimple_cond_rhs (stmt));
       else if (gswitch *swtch_stmt = dyn_cast <gswitch *> (stmt))
        val = gimple_switch_index (swtch_stmt);
 
@@ -1946,6 +1945,8 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si,
                    gimple_cond_make_true (as_a <gcond *> (stmt));
                  else
                    gcc_unreachable ();
+
+                 gimple_set_modified (stmt, true);
                }
 
              /* Further simplifications may be possible.  */
@@ -1953,6 +1954,8 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si,
            }
        }
 
+      update_stmt_if_modified (stmt);
+
       /* If we simplified a statement in such a way as to be shown that it
         cannot trap, update the eh information and the cfg to match.  */
       if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))