public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR67909 PR67947]
@ 2015-10-13 11:57 Yuri Rumyantsev
  2015-10-13 12:38 ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Yuri Rumyantsev @ 2015-10-13 11:57 UTC (permalink / raw)
  To: gcc-patches, Richard Biener, Igor Zamyatin

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Hi All,

Here is a simple patch for unswitching outer loop through guard-edge
hoisting. The check that guard-edge is around the inner loop was
missed.

Bootstrapping and regression testing did not show new failures.

Is it OK for trunk?

ChangeLog:
2014-10-13  Yuri Rumyantsev  <ysrumyan@gmail.com>

PR tree-optimization/67909, 67947
* tree-ssa-loop-unswitch.c (find_loop_guard): Add check that GUARD_EDGE
really skip the inner loop.

gcc/testsuite/ChangeLog
* gcc.dg/torture/pr67947.c: New test.

[-- Attachment #2: patch --]
[-- Type: application/octet-stream, Size: 1604 bytes --]

diff --git a/gcc/testsuite/gcc.dg/torture/pr67947.c b/gcc/testsuite/gcc.dg/torture/pr67947.c
new file mode 100644
index 0000000..5664c48
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr67947.c
@@ -0,0 +1,30 @@
+/* { dg-additional-options "-O3" } */
+
+#include <stdlib.h>
+
+int a;
+int c;
+__attribute__((noinline, noclone)) void foo (int x)
+{
+  if (x == 0)
+    c++;
+}
+
+int
+main (int argc, char* argv[])
+{
+  int j, k, b = 0;
+  if (argc == 0)
+    b = 1;
+  for (j = 0; j < 3; j++)
+    for (k = 0; k < 1; k++)
+      {
+	foo (0);
+	if (b)
+	  for (k = -1; a;)
+	    ;
+      }
+  if (c != 3)
+    abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index 4328d6a..ba8a29e 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -466,7 +466,6 @@ find_loop_guard (struct loop *loop)
 {
   basic_block header = loop->header;
   edge guard_edge, te, fe;
-  /* bitmap processed, known_invariants;*/
   basic_block *body = NULL;
   unsigned i;
   tree use;
@@ -524,6 +523,15 @@ find_loop_guard (struct loop *loop)
   else
     return NULL;
 
+  /* Guard edge must skip inner loop.  */
+  if (!dominated_by_p (CDI_DOMINATORS, loop->inner->header,
+      guard_edge == fe ? te->dest : fe->dest))
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	fprintf (dump_file, "Guard edge %d --> %d is not around the loop!\n",guard_edge->src->index,guard_edge->dest->index);
+      return NULL;
+    }
+
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file,
 	     "Considering guard %d -> %d in loop %d\n",

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-13 12:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-13 11:57 [PATCH PR67909 PR67947] Yuri Rumyantsev
2015-10-13 12:38 ` H.J. Lu
2015-10-13 12:49   ` Yuri Rumyantsev
2015-10-13 12:53     ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).