public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4739] loop-invariant: Split preheader edge if the preheader bb ends with jump [PR106751]
Date: Fri, 16 Dec 2022 09:20:35 +0000 (GMT)	[thread overview]
Message-ID: <20221216092035.24062383AB59@sourceware.org> (raw)

https://gcc.gnu.org/g:ddcaa60983b50378bde1b7e327086fe0ce101795

commit r13-4739-gddcaa60983b50378bde1b7e327086fe0ce101795
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 16 10:19:22 2022 +0100

    loop-invariant: Split preheader edge if the preheader bb ends with jump [PR106751]
    
    The RTL loop passes only request simple preheaders, but don't require
    fallthru preheaders, while move_invariant_reg apparently assumes the
    latter, that it can just append instruction(s) to the end of the preheader
    basic block.
    
    The following patch fixes that by splitting the preheader edge if
    the preheader bb ends with a JUMP_INSN (asm goto in this case).
    Without that we get control flow in the middle of a bb.
    
    2022-12-16  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/106751
            * loop-invariant.cc (move_invariant_reg): If preheader bb ends
            with a JUMP_INSN, split the preheader edge and emit invariants
            into the new preheader basic block.
    
            * gcc.c-torture/compile/pr106751.c: New test.

Diff:
---
 gcc/loop-invariant.cc                          |  2 ++
 gcc/testsuite/gcc.c-torture/compile/pr106751.c | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/gcc/loop-invariant.cc b/gcc/loop-invariant.cc
index f3248540fb1..9b5f6cd3223 100644
--- a/gcc/loop-invariant.cc
+++ b/gcc/loop-invariant.cc
@@ -1837,6 +1837,8 @@ move_invariant_reg (class loop *loop, unsigned invno)
       else if (dump_file)
 	fprintf (dump_file, "Invariant %d moved without introducing a new "
 			    "temporary register\n", invno);
+      if (JUMP_P (BB_END (preheader)))
+	preheader = split_edge (loop_preheader_edge (loop));
       reorder_insns (inv->insn, inv->insn, BB_END (preheader));
       df_recompute_luids (preheader);
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106751.c b/gcc/testsuite/gcc.c-torture/compile/pr106751.c
new file mode 100644
index 00000000000..5fbf93bd332
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr106751.c
@@ -0,0 +1,17 @@
+/* PR rtl-optimization/106751 */
+
+int *foo (void);
+
+void
+bar (void)
+{
+  asm goto ("" : : : : lab);
+  __builtin_unreachable ();
+lab:
+  while (1)
+    {
+      int o;
+      asm ("" : "=r" (o) : "g" (1));
+      *foo () = o;
+    }
+}

                 reply	other threads:[~2022-12-16  9:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221216092035.24062383AB59@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).