https://gcc.gnu.org/g:b4198699bb515f098057b0d00a3ca67adbbc4f17
commit r17-4890-gb4198699bb515f098057b0d00a3ca67adbbc4f17 Author: Aldy Hernandez <[email protected]> Date: Sun Oct 4 10:02:31 2026 +0000 DOM: remove the boolean range special case for conditionals optimize_stmt turns if (b == 5) into if (0 == 5) when b has a [0, 1] range. We're already calling simplify_stmt which takes care of this. Remove the code. Tested on ppc64le Linux. Over a corpus of .ii files from a stage1 bootstrap the assembly of two TUs changes, cp-lex.cc one instruction larger and simplify-rtx.cc four smaller. gcc/ChangeLog: * tree-ssa-dom.cc (dom_opt_dom_walker::optimize_stmt): Remove the boolean range special case. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-dom-simplify-4.c: New test. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c | 30 ++++++++++++++++++++++ gcc/tree-ssa-dom.cc | 25 ------------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c new file mode 100644 index 000000000000..67f548f2f08c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -fno-tree-vrp -fdump-tree-dom2" } */ + +/* b is 0 or 1, so the test against 5 is false. */ + +void frob (void); + +void __GIMPLE (ssa,startwith("dom")) +f (int x, int y) +{ + _Bool b; + int i; + + __BB(2): + b_1 = x_2(D) < y_3(D); + i_4 = (int) b_1; + if (i_4 == 5) + goto __BB3; + else + goto __BB4; + + __BB(3): + frob (); + goto __BB4; + + __BB(4): + return; +} + +/* { dg-final { scan-tree-dump "Folding predicate i_4 == 5 to 0" "dom2" } } */ diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 490eddc37c38..f48be8d68dd6 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -2325,31 +2325,6 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si, } } - if (gimple_code (stmt) == GIMPLE_COND) - { - tree lhs = gimple_cond_lhs (stmt); - tree rhs = gimple_cond_rhs (stmt); - - /* If the LHS has a range [0..1] and the RHS has a range ~[0..1], - then this conditional is computable at compile time. We can just - shove either 0 or 1 into the LHS, mark the statement as modified - and all the right things will just happen below. - - Note this would apply to any case where LHS has a range - narrower than its type implies and RHS is outside that - narrower range. Future work. */ - if (TREE_CODE (lhs) == SSA_NAME - && ssa_name_has_boolean_range (lhs) - && TREE_CODE (rhs) == INTEGER_CST - && ! (integer_zerop (rhs) || integer_onep (rhs))) - { - gimple_cond_set_lhs (as_a <gcond *> (stmt), - fold_convert (TREE_TYPE (lhs), - integer_zero_node)); - gimple_set_modified (stmt, true); - } - } - update_stmt_if_modified (stmt); eliminate_redundant_computations (si, m_const_and_copies, m_avail_exprs_stack);
