On Sun, Jun 8, 2025 at 1:06 AM Andrew Pinski <quic_apin...@quicinc.com> wrote: > > Since r13-707-g68e0063397ba82 COND_EXPR in gimple assign does > not have a special case for COND_EXPR and conditional as the first operand. > This removes the code from tree-ssa-math-opts.cc which was for that special > case. > > Bootstrapped and tested on x86_64-linux-gnu. > > PR tree-optimization/120477 > gcc/ChangeLog: > > * tree-ssa-math-opts.cc (maybe_optimize_guarding_check): Remove > special case for COND_EXPR. > (arith_overflow_check_p): Likewise. > (match_arith_overflow): Likewise, changing into a gcc_unreachable. > > Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> > --- > gcc/tree-ssa-math-opts.cc | 58 ++------------------------------------- > 1 file changed, 3 insertions(+), 55 deletions(-) > > diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc > index 7e819f37446..d5f18540ffd 100644 > --- a/gcc/tree-ssa-math-opts.cc > +++ b/gcc/tree-ssa-math-opts.cc > @@ -3775,20 +3775,7 @@ maybe_optimize_guarding_check (vec<gimple *> > &mul_stmts, gimple *cond_stmt, > if (gimple_phi_arg_def (phi, succ_edge->dest_idx) != lhs) > return; > tree other_val = gimple_phi_arg_def (phi, other_edge->dest_idx); > - if (gimple_assign_rhs_code (cond_stmt) == COND_EXPR) > - { > - tree cond = gimple_assign_rhs1 (cond_stmt); > - if (TREE_CODE (cond) == NE_EXPR) > - { > - if (!operand_equal_p (other_val, > - gimple_assign_rhs3 (cond_stmt), 0)) > - return; > - } > - else if (!operand_equal_p (other_val, > - gimple_assign_rhs2 (cond_stmt), 0)) > - return;
So this last check would still do something - it's not clear from the context that we can elide this? Shouldn't we keep if (gimple_assign_rhs_code (cond_stmt) == COND_EXPR) return; as you remove all COND_EXPR handling elsewhere? Jakub probably knows this code best. Richard. > - } > - else if (gimple_assign_rhs_code (cond_stmt) == NE_EXPR) > + if (gimple_assign_rhs_code (cond_stmt) == NE_EXPR) > { > if (!integer_zerop (other_val)) > return; > @@ -3903,18 +3890,6 @@ arith_overflow_check_p (gimple *stmt, gimple > *cast_stmt, gimple *&use_stmt, > crhs1 = gimple_assign_rhs1 (cur_use_stmt); > crhs2 = gimple_assign_rhs2 (cur_use_stmt); > } > - else if (gimple_assign_rhs_code (cur_use_stmt) == COND_EXPR) > - { > - tree cond = gimple_assign_rhs1 (cur_use_stmt); > - if (COMPARISON_CLASS_P (cond)) > - { > - ccode = TREE_CODE (cond); > - crhs1 = TREE_OPERAND (cond, 0); > - crhs2 = TREE_OPERAND (cond, 1); > - } > - else > - return 0; > - } > else > return 0; > } > @@ -3947,18 +3922,6 @@ arith_overflow_check_p (gimple *stmt, gimple > *cast_stmt, gimple *&use_stmt, > crhs1 = gimple_assign_rhs1 (cur_use_stmt); > crhs2 = gimple_assign_rhs2 (cur_use_stmt); > } > - else if (gimple_assign_rhs_code (cur_use_stmt) == COND_EXPR) > - { > - tree cond = gimple_assign_rhs1 (cur_use_stmt); > - if (COMPARISON_CLASS_P (cond)) > - { > - ccode = TREE_CODE (cond); > - crhs1 = TREE_OPERAND (cond, 0); > - crhs2 = TREE_OPERAND (cond, 1); > - } > - else > - return 0; > - } > else > { > enum tree_code sc = gimple_assign_rhs_code (cur_use_stmt); > @@ -4827,15 +4790,7 @@ match_arith_overflow (gimple_stmt_iterator *gsi, > gimple *stmt, > else if (gimple_assign_cast_p (use_stmt)) > gimple_assign_set_rhs1 (use_stmt, ovf); > else > - { > - tree_code sc = gimple_assign_rhs_code (use_stmt); > - gcc_checking_assert (sc == COND_EXPR); > - tree cond = gimple_assign_rhs1 (use_stmt); > - cond = build2 (TREE_CODE (cond), > - boolean_type_node, ovf, > - build_int_cst (type, 0)); > - gimple_assign_set_rhs1 (use_stmt, cond); > - } > + gcc_unreachable(); > } > update_stmt (use_stmt); > gsi_remove (&gsiu, true); > @@ -4853,14 +4808,7 @@ match_arith_overflow (gimple_stmt_iterator *gsi, > gimple *stmt, > } > } > else > - { > - gcc_checking_assert (gimple_assign_rhs_code (use_stmt) > - == COND_EXPR); > - tree cond = build2 (ovf_use == 1 ? NE_EXPR : EQ_EXPR, > - boolean_type_node, ovf, > - build_int_cst (type, 0)); > - gimple_assign_set_rhs1 (use_stmt, cond); > - } > + gcc_unreachable (); > } > update_stmt (use_stmt); > if (code == MULT_EXPR && use_stmt != orig_use_stmt) > -- > 2.43.0 >