]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
loop-invariant: Split preheader edge if the preheader bb ends with jump [PR106751]
authorJakub Jelinek <jakub@redhat.com>
Fri, 16 Dec 2022 09:19:22 +0000 (10:19 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 3 May 2023 11:48:15 +0000 (13:48 +0200)
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.c (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.

(cherry picked from commit ddcaa60983b50378bde1b7e327086fe0ce101795)

gcc/loop-invariant.c
gcc/testsuite/gcc.c-torture/compile/pr106751.c [new file with mode: 0644]

index 3a9fcfabce84bebf91c0a71d488f76e7290194f9..9809a8c93414008a0e9bb987a8188a2f29c1d81a 100644 (file)
@@ -1829,6 +1829,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 (file)
index 0000000..5fbf93b
--- /dev/null
@@ -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;
+    }
+}