]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
DOM should not process unreachable if there is an SSA relation.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 3 Jun 2026 21:46:03 +0000 (17:46 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Fri, 5 Jun 2026 19:07:04 +0000 (15:07 -0400)
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.

gcc/testsuite/gcc.dg/pr125501.c [new file with mode: 0644]
gcc/tree-ssa-dom.cc

diff --git a/gcc/testsuite/gcc.dg/pr125501.c b/gcc/testsuite/gcc.dg/pr125501.c
new file mode 100644 (file)
index 0000000..22cdd3f
--- /dev/null
@@ -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);
+}
index e54058ce6fa13858f4cabd1701cee0c41b251e7c..02ffcbfc67715b7d219f1c205431c28c9ef93350 100644 (file)
@@ -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)