https://gcc.gnu.org/g:8f91f1288ad46df7038f66e64a8f25ce285480f1
commit r17-4938-g8f91f1288ad46df7038f66e64a8f25ce285480f1 Author: Aldy Hernandez <[email protected]> Date: Mon Oct 5 10:48:43 2026 +0000 DOM: stop rewriting comparisons into equalities Instead of keeping the test_for_singularity() functionality we are now doing with simplify_using_ranges::simplify(), just do simplify_using_ranges::fold_cond() which folds the conditional to a constant if possible, but avoids the singularity transformation. This transformation isn't needed as ranger already knows what x is on each arm of the conditional. Besides, this transformation was problematic for loop analyzers. Also, keep assignments from going through the simplifier, since this was a side-effect of the last patch. Tested on ppc64le Linux. gcc/ChangeLog: * tree-ssa-dom.cc (dom_opt_dom_walker::simplify_stmt): Rename to... (dom_opt_dom_walker::fold_cond): ...this. Fold a conditional with the ranger, do not simplify anything else. (dom_opt_dom_walker::optimize_stmt): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/predcom-7.c: Drop -fno-tree-dominator-opts. * gcc.dg/tree-ssa/ssa-dom-simplify-3.c: Expect the relationals to stay. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c | 5 +--- gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-3.c | 5 ++-- gcc/tree-ssa-dom.cc | 31 ++++++---------------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c index 0a1bc5b3a2b8..999397675622 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c @@ -1,8 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -fdump-tree-pcom-details-blocks -fno-tree-dominator-opts" } */ -/* DOM folds the exit test to c + 1 == 1 from c's range, which leaves c a - two-valued PHI rather than an induction variable and predcom nothing to - do; keep it out of the way. */ +/* { dg-options "-O3 -fdump-tree-pcom-details-blocks" } */ int b, f, d[5][2]; unsigned int c; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-3.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-3.c index 89d545e621d3..20e5ee69c20c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-3.c @@ -86,6 +86,7 @@ by_range_min (int a, int b) return 0; } -/* { dg-final { scan-tree-dump "if \\(x_1\\(D\\) == 4\\)" "dom2" } } */ -/* { dg-final { scan-tree-dump "if \\(i_1\\(D\\) == j_2\\(D\\)\\)" "dom2" } } */ +/* DOM leaves the relationals alone. */ +/* { dg-final { scan-tree-dump-not "if \\(x_1\\(D\\) == 4\\)" "dom2" } } */ +/* { dg-final { scan-tree-dump-not "if \\(i_1\\(D\\) == j_2\\(D\\)\\)" "dom2" } } */ /* { dg-final { scan-tree-dump-not "MIN_EXPR" "dom2" } } */ diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 7a30983572b7..1470d65f4e3c 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -694,7 +694,7 @@ private: void set_global_ranges_from_unreachable_edges (basic_block); - void simplify_stmt (gimple_stmt_iterator *); + void fold_cond (gimple *); void record_equivalences_from_incoming_edge (basic_block); void eliminate_redundant_computations (gimple_stmt_iterator *); void record_equivalences_from_stmt (gimple *, int); @@ -1983,32 +1983,18 @@ cprop_operand (gimple *stmt, use_operand_p op_p, range_query *query) } } -/* Attempt to simplify the statement in GSI with range info. */ +/* Fold the conditional STMT with range info. */ void -dom_opt_dom_walker::simplify_stmt (gimple_stmt_iterator *gsi) +dom_opt_dom_walker::fold_cond (gimple *stmt) { - gimple *stmt = gsi_stmt (*gsi); - - /* Avoid switches as touching those could remove edges mid-walk. */ - if (gimple_code (stmt) == GIMPLE_SWITCH) + gcond *cond = dyn_cast <gcond *> (stmt); + if (!cond) return; - gimple_stmt_iterator i = *gsi; - gsi_prev (&i); - gimple *before = gsi_end_p (i) ? NULL : gsi_stmt (i); simplify_using_ranges simplify (m_ranger); - if (!simplify.simplify (gsi)) - return; - - stmt = gsi_stmt (*gsi); - gimple_set_modified (stmt, true); - - /* Our main loop will go back over the statements inserted in front of STMT, - so mark those as visited to avoid looking at them again. */ - i = *gsi; - for (gsi_prev (&i); !gsi_end_p (i) && gsi_stmt (i) != before; gsi_prev (&i)) - gimple_set_visited (gsi_stmt (i), true); + if (simplify.fold_cond (cond)) + gimple_set_modified (cond, true); } /* CONST_AND_COPIES is a table which maps an SSA_NAME to the current @@ -2269,8 +2255,7 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si, it, which may in turn allow other part of DOM or other passes to do a better job. */ if (!gimple_modified_p (stmt)) - simplify_stmt (si); - stmt = gsi_stmt (*si); + fold_cond (stmt); } /* Record any additional equivalences created by this statement. */
