From: Yuri Rumyantsev <ysrumyan@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
Richard Biener <richard.guenther@gmail.com>,
Igor Zamyatin <izamyatin@gmail.com>
Subject: [PATCH PR67909 PR67947]
Date: Tue, 13 Oct 2015 11:57:00 -0000 [thread overview]
Message-ID: <CAEoMCqR-LXyr8xbbH6=CT0rJNSmpKTG+za257RO6Gc13RWcHyg@mail.gmail.com> (raw)
[-- 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",
next reply other threads:[~2015-10-13 11:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-13 11:57 Yuri Rumyantsev [this message]
2015-10-13 12:38 ` H.J. Lu
2015-10-13 12:49 ` Yuri Rumyantsev
2015-10-13 12:53 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEoMCqR-LXyr8xbbH6=CT0rJNSmpKTG+za257RO6Gc13RWcHyg@mail.gmail.com' \
--to=ysrumyan@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=izamyatin@gmail.com \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).