tree-optimization/96349 - avoid abnormal coalescing issues in loop split
authorRichard Biener <rguenther@suse.de>
Tue, 28 Jul 2020 07:45:52 +0000 (09:45 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 29 Jul 2020 11:30:14 +0000 (13:30 +0200)
This avoids splitting a loop when the entry value of a loop PHI is
involved with abnormal coalescing.

2020-07-28  Richard Biener  <rguenther@suse.de>

PR tree-optimization/96349
* tree-ssa-loop-split.c (stmt_semi_invariant_p_1): When the
condition runs into a loop PHI with an abnormal entry value give up.

* gcc.dg/torture/pr96349.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr96349.c [new file with mode: 0644]
gcc/tree-ssa-loop-split.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr96349.c b/gcc/testsuite/gcc.dg/torture/pr96349.c
new file mode 100644 (file)
index 0000000..4ce3949
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+void __attribute__ ((returns_twice))
+gr (void);
+
+void
+ib (void);
+
+void
+zg (void);
+
+void
+yw (int uz)
+{
+  gr ();
+
+  for (;;)
+    if (uz != 0)
+      {
+        uz = 0;
+        ib ();
+      }
+    else
+      zg ();
+}
index 7de95b5888428d28c0b323a50fe92cd0fe864766..1eb6be5ddb24be6e73237ae19ea1c57da15565a8 100644 (file)
@@ -1145,6 +1145,16 @@ stmt_semi_invariant_p_1 (struct loop *loop, gimple *stmt,
 
       if (gimple_bb (stmt) == loop->header)
        {
+         /* If the entry value is subject to abnormal coalescing
+            avoid the transform since we're going to duplicate the
+            loop header and thus likely introduce overlapping life-ranges
+            between the PHI def and the entry on the path when the
+            first loop is skipped.  */
+         tree entry_def
+           = PHI_ARG_DEF_FROM_EDGE (phi, loop_preheader_edge (loop));
+         if (TREE_CODE (entry_def) == SSA_NAME
+             && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (entry_def))
+           return false;
          invar = loop_iter_phi_semi_invariant_p (loop, phi, skip_head);
          return invar;
        }