[gcc r17-3187] Add --param=dom-jump-threading to disable DOM jump threading [PR126103]

Aldy Hernandez via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:8a8a022c81b6105f70f72dfe2dc7b368353b49e6

commit r17-3187-g8a8a022c81b6105f70f72dfe2dc7b368353b49e6
Author: Aldy Hernandez <[email protected]>
Date:   Mon Aug 10 06:59:36 2026 +0000

    Add --param=dom-jump-threading to disable DOM jump threading [PR126103]
    
    As discussed in PR126103, the first step to removing DOM is untangling
    its threader from the rest of DOM.  I've started auditing what we're
    missing in PRE + backwards threader, and need a way to disable DOM's
    threading for the barrage of PRs I'm about to file.
    
    We already have a way to disable all jump threads, but no way to
    disable just DOM's.  This patch does jhust this with
    --param=dom-jump-threading=[01].  It's in line with what we
    temporarily did for ranger-threading and ranger VRP.
    
    The --param disables jump threading in DOM, but everything else DOM
    does is unaffected.
    
    Tested on ppc64le Linux.
    
            PR tree-optimization/126103
    
    gcc/ChangeLog:
    
            * doc/params.texi (dom-jump-threading): Document.
            * params.opt (-param=dom-jump-threading=): New.
            * tree-ssa-dom.cc (dom_opt_dom_walker::after_dom_children): Honor
            param_dom_jump_threading.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/dom-jump-threading-1.c: New test.
            * gcc.dg/tree-ssa/dom-jump-threading-2.c: New test.

Diff:
---
 gcc/doc/params.texi                                |  6 ++++++
 gcc/params.opt                                     |  4 ++++
 .../gcc.dg/tree-ssa/dom-jump-threading-1.c         | 24 ++++++++++++++++++++++
 .../gcc.dg/tree-ssa/dom-jump-threading-2.c         | 22 ++++++++++++++++++++
 gcc/tree-ssa-dom.cc                                |  3 ++-
 5 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/params.texi b/gcc/doc/params.texi
index 26b34a59aa98..e69be2d2923e 100644
--- a/gcc/doc/params.texi
+++ b/gcc/doc/params.texi
@@ -894,6 +894,12 @@ optimizing.
 Maximum number of dominators BBs to walk when simplifying loop bounds
 and conditions.
 
+@paindex dom-jump-threading
+@item dom-jump-threading
+Enable jump threading in the dominator optimizer pass.  Disabling it
+is useful to isolate the jump threads found by the backward threader,
+which runs regardless.
+
 @paindex max-jump-thread-duplication-stmts
 @item max-jump-thread-duplication-stmts
 Maximum number of statements allowed in a block that needs to be
diff --git a/gcc/params.opt b/gcc/params.opt
index 044c4a10bc44..0c6a3e514574 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -138,6 +138,10 @@ Probability that COMDAT function is shared with a different compilation unit.
 Common Joined UInteger Var(param_cxx_max_namespaces_for_diagnostic_help) Init(1000) Param
 Maximum number of namespaces to search for alternatives when name lookup fails.
 
+-param=dom-jump-threading=
+Common Joined UInteger Var(param_dom_jump_threading) Init(1) IntegerRange(0, 1) Param Optimization
+Enable jump threading in the dominator optimizer pass.
+
 -param=dse-max-alias-queries-per-store=
 Common Joined UInteger Var(param_dse_max_alias_queries_per_store) Init(256) Param Optimization
 Maximum number of queries into the alias oracle per store.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-1.c b/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-1.c
new file mode 100644
index 000000000000..a0d0809b1763
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-1.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 --param=dom-jump-threading=0 -fdump-tree-dom2-details -fdump-tree-optimized" } */
+
+/* Verify that --param=dom-jump-threading=0 keeps DOM from threading
+   jumps.  Only DOM can thread a PHI of compares (the backward
+   threader cannot resolve the exit conditional to a single edge), so
+   with the param off the join block and its PHI must survive.  */
+
+void g (void);
+
+void
+f (int x, int a, int b, int c, int d)
+{
+  _Bool t;
+  if (x)
+    t = a < b;
+  else
+    t = c < d;
+  if (t)
+    g ();
+}
+
+/* { dg-final { scan-tree-dump-not "Registering jump thread" "dom2" } } */
+/* { dg-final { scan-tree-dump "PHI <" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-2.c b/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-2.c
new file mode 100644
index 000000000000..fb6b8a12732c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-2.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dom2-details" } */
+
+/* Same test as dom-jump-threading-1.c but with DOM jump threading at
+   its default (enabled): DOM must thread the PHI of compares, which
+   keeps the sibling test honest.  */
+
+void g (void);
+
+void
+f (int x, int a, int b, int c, int d)
+{
+  _Bool t;
+  if (x)
+    t = a < b;
+  else
+    t = c < d;
+  if (t)
+    g ();
+}
+
+/* { dg-final { scan-tree-dump "Registering jump thread" "dom2" } } */
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 02ffcbfc6771..7fded792a3c0 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1801,7 +1801,8 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
 void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
-  m_threader->thread_outgoing_edges (bb);
+  if (param_dom_jump_threading)
+    m_threader->thread_outgoing_edges (bb);
   bitmap_clear_bit (m_state->get_blocks_on_stack (), bb->index);
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
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.