public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6222] shrink-wrap: Don't put on incoming EDGE_CROSSING [PR98289]
@ 2020-12-17 12:30 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-12-17 12:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:62cb9680e592057a49de66eac34da679338932f9

commit r11-6222-g62cb9680e592057a49de66eac34da679338932f9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 17 13:28:48 2020 +0100

    shrink-wrap: Don't put on incoming EDGE_CROSSING [PR98289]
    
    As mentioned in the PR, shrink-wrapping disqualifies for prologue
    placement basic blocks that have EDGE_CROSSING incoming edge.
    I don't see why that is necessary, those edges seem to be redirected
    just fine, both on x86_64 and powerpc64.  In the former case, they
    are usually conditional jumps that patch_jump_insn can handle just fine,
    after all, they were previously crossing and will be crossing after
    the redirection too, just to a different label.  And in the powerpc64
    case, it is a simple_jump instead that again seems to be handled by
    patch_jump_insn just fine.
    Sure, redirecting an edge that was previously not crossing to be crossing or
    vice versa can fail, but that is not what shrink-wrapping needs.
    Also tested in GCC 8 with this patch and don't see ICEs there either
    (though, of course, I'm not suggesting we should backport this to release
    branches).
    The old ICEs could have been fixed by PR87475 fix or some other one
    years ago.
    
    2020-12-17  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/98289
            * shrink-wrap.c (can_get_prologue): Don't punt on EDGE_CROSSING
            incoming edges.
    
            * gcc.target/i386/pr98289.c: New test.
            * gcc.dg/torture/pr98289.c: New test.

Diff:
---
 gcc/shrink-wrap.c                       |  2 +-
 gcc/testsuite/gcc.dg/torture/pr98289.c  | 52 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr98289.c | 54 +++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c
index d70635e94a3..4bb63e9b5d8 100644
--- a/gcc/shrink-wrap.c
+++ b/gcc/shrink-wrap.c
@@ -494,7 +494,7 @@ can_get_prologue (basic_block pro, HARD_REG_SET prologue_clobbered)
   edge e;
   edge_iterator ei;
   FOR_EACH_EDGE (e, ei, pro->preds)
-    if (e->flags & (EDGE_COMPLEX | EDGE_CROSSING)
+    if (e->flags & EDGE_COMPLEX
 	&& !dominated_by_p (CDI_DOMINATORS, e->src, pro))
       return false;
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr98289.c b/gcc/testsuite/gcc.dg/torture/pr98289.c
new file mode 100644
index 00000000000..07094a1a08c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr98289.c
@@ -0,0 +1,52 @@
+/* PR rtl-optimization/98289 */
+/* { dg-do compile { target freorder } } */
+/* { dg-options "-O2 -freorder-blocks-and-partition" } */
+
+int bar (void) __attribute__((cold));
+
+void
+foo (int x)
+{
+  if (x)
+    __builtin_abort ();
+}
+
+void
+baz (int x)
+{
+  if (__builtin_expect (x, 0))
+    {
+      bar ();
+      bar ();
+      bar ();
+    }
+}
+
+void
+qux (int x, int y, int z, int w)
+{
+  if (x || y || z || w)
+    __builtin_abort ();
+}
+
+int
+corge (int x, int y, int z, int w, int u)
+{
+  if (__builtin_expect (x, 0))
+    goto lab;
+  u++;
+  if (__builtin_expect (y, 0))
+    goto lab;
+  u *= 2;
+  if (__builtin_expect (z, 0))
+    goto lab;
+  u |= 42;
+  if (__builtin_expect (w, 0))
+    {
+      lab:;
+      bar ();
+      bar ();
+      if (bar () > 32) goto lab;
+    }
+  return u;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr98289.c b/gcc/testsuite/gcc.target/i386/pr98289.c
new file mode 100644
index 00000000000..9c620d40164
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr98289.c
@@ -0,0 +1,54 @@
+/* PR rtl-optimization/98289 */
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target freorder } */
+/* { dg-options "-O2 -freorder-blocks-and-partition -fdump-rtl-pro_and_epilogue-details" } */
+/* { dg-final { scan-rtl-dump-times "Performing shrink-wrapping" 4 "pro_and_epilogue" } } */
+
+int bar (void) __attribute__((cold));
+
+void
+foo (int x)
+{
+  if (x)
+    __builtin_abort ();
+}
+
+void
+baz (int x)
+{
+  if (__builtin_expect (x, 0))
+    {
+      bar ();
+      bar ();
+      bar ();
+    }
+}
+
+void
+qux (int x, int y, int z, int w)
+{
+  if (x || y || z || w)
+    __builtin_abort ();
+}
+
+int
+corge (int x, int y, int z, int w, int u)
+{
+  if (__builtin_expect (x, 0))
+    goto lab;
+  u++;
+  if (__builtin_expect (y, 0))
+    goto lab;
+  u *= 2;
+  if (__builtin_expect (z, 0))
+    goto lab;
+  u |= 42;
+  if (__builtin_expect (w, 0))
+    {
+      lab:;
+      bar ();
+      bar ();
+      if (bar () > 32) goto lab;
+    }
+  return u;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-17 12:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 12:30 [gcc r11-6222] shrink-wrap: Don't put on incoming EDGE_CROSSING [PR98289] Jakub Jelinek

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).