]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add --param=dom-jump-threading to disable DOM jump threading [PR126103] master trunk
authorAldy Hernandez <aldy@quesejoda.com>
Mon, 10 Aug 2026 06:59:36 +0000 (06:59 +0000)
committerAldy Hernandez <aldy@quesejoda.com>
Mon, 10 Aug 2026 12:31:01 +0000 (14:31 +0200)
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.

gcc/doc/params.texi
gcc/params.opt
gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/dom-jump-threading-2.c [new file with mode: 0644]
gcc/tree-ssa-dom.cc

index 26b34a59aa98f71870c4c82aef6b1fdb531a8c90..e69be2d2923e4fd78cf86f6f5513f06527bb5780 100644 (file)
@@ -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
index 044c4a10bc44fa894830afb0f25ec56b156d10ff..0c6a3e514574990e302f5019ea1b75e705e51c86 100644 (file)
@@ -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 (file)
index 0000000..a0d0809
--- /dev/null
@@ -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 (file)
index 0000000..fb6b8a1
--- /dev/null
@@ -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" } } */
index 02ffcbfc67715b7d219f1c205431c28c9ef93350..7fded792a3c0e3abbe3d40fff5fa7aa0b7fb9506 100644 (file)
@@ -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 ();