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

commit r17-1381-geeaf2211377a55b1126b04ebf27b46535e79c771
Author: Andrew MacLeod <[email protected]>
Date:   Wed Jun 3 17:46:03 2026 -0400

    DOM should not process unreachable if there is an SSA relation.
    
    DOM should follow VRP's lead and not attempt o assign global values to
    SSA names when the branch leading to a __builtin_unreachable () has
    2 ssa-names.  Relations elsewhere may lead to this being invalid.
    
            PR tree-optimization/125501
            gcc/
            * tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Abort
            if there are 2 SSA_NAMES on the branch condition.
            gcc/testsuite/
            * gcc.dg/pr125501.c: New.

Diff:
---
 gcc/testsuite/gcc.dg/pr125501.c | 35 +++++++++++++++++++++++++++++++++++
 gcc/tree-ssa-dom.cc             |  6 ++++++
 2 files changed, 41 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/pr125501.c b/gcc/testsuite/gcc.dg/pr125501.c
new file mode 100644
index 000000000000..22cdd3f28f6c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr125501.c
@@ -0,0 +1,35 @@
+// { dg-do run }
+// { dg-options "-O3" }
+
+#include <stdint.h>
+int64_t g2, g27, g10;
+static void *g13, *g24;
+_Bool f11___trans_tmp_1, f11_c17;
+void __attribute__((noinline)) f11(int64_t a0, void *a4, void *a5)
+{
+    _Bool ob6;
+    int32_t v12;
+    int64_t v15;
+lbl_entry:
+lbl_sw_def4:
+    ob6 = g13 == a4;
+    if (ob6 || f11_c17) return;
+    if (f11___trans_tmp_1) v12 = g10;
+    a0 = (char *)a5 - (char *)a4;
+    ob6 = 0 == a0;
+    *(_Bool *)4 = 0;
+    if (ob6) goto lbl_b22;
+    __builtin_unreachable();
+lbl_b22:
+    g27 = v12;
+    switch (v15)
+    {
+        case 6009053803839173278: goto lbl_sw_def4;
+        case 70689892217558167: goto lbl_entry;
+    }
+}
+
+int main()
+{
+    f11(0, 0, g24);
+}
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index e54058ce6fa1..02ffcbfc6771 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1437,6 +1437,12 @@ 
dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb)
       || !assert_unreachable_fallthru_edge_p (pred_e))
     return;
 
+  // Bail if the condition leading to the unreachable edge has 2 ssa-names.
+  // See PR 125501.
+  if ((TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME
+      && TREE_CODE (gimple_cond_rhs (stmt)) == SSA_NAME))
+    return;
+
   tree name;
   FOR_EACH_GORI_EXPORT_NAME (m_ranger->gori_ssa (), pred_e->src, name)
     if (all_uses_feed_or_dominated_by_stmt (name, stmt)

Reply via email to