[gcc r15-11488] tree-optimization/125545 - reassoc insering after asm goto

Richard Biener via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:65f32ce9f4f7d84087cb0f03c3d256da82031b0a

commit r15-11488-g65f32ce9f4f7d84087cb0f03c3d256da82031b0a
Author: Richard Biener <[email protected]>
Date:   Tue Jun 2 14:56:12 2026 +0200

    tree-optimization/125545 - reassoc insering after asm goto
    
    There's one case we can handle just fine which is when the asm goto
    has a single successor (it's fallthru edge, possibly shared with
    an asm goto label).  As we're using dominance based insertion
    point discovery we have to handle this case.
    
            PR tree-optimization/125545
            * tree-ssa-reassoc.cc (insert_stmt_after): Allow asm goto
            with a single successor.
    
            * gcc.dg/torture/pr125545.c: New testcase.
    
    (cherry picked from commit 31c818a7ff8f090e58379c52c7589f2e6e35de20)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr125545.c | 9 +++++++++
 gcc/tree-ssa-reassoc.cc                 | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr125545.c b/gcc/testsuite/gcc.dg/torture/pr125545.c
new file mode 100644
index 000000000000..084ce567851a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr125545.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+int b(int c)
+{
+  int a;
+  __asm__ goto("" : "=r"(a) : : : d);
+d:
+  return c && a != 42 && a >= 42;
+}
diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc
index 2239b83352b6..8f7e41b24b18 100644
--- a/gcc/tree-ssa-reassoc.cc
+++ b/gcc/tree-ssa-reassoc.cc
@@ -1521,7 +1521,8 @@ insert_stmt_after (gimple *stmt, gimple *insert_point)
       return;
     }
   else if (gimple_code (insert_point) == GIMPLE_ASM
-	   && gimple_asm_nlabels (as_a <gasm *> (insert_point)) != 0)
+	   && gimple_asm_nlabels (as_a <gasm *> (insert_point)) != 0
+	   && !single_succ_p (gimple_bb (insert_point)))
     /* We have no idea where to insert - it depends on where the
        uses will be placed.  */
     gcc_unreachable ();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.