To speed up things slightly so not needing to call all the way through to match and simplify, we should return early for true/false on GIMPLE_COND.
gcc/ChangeLog: * gimple-fold.cc (fold_stmt_1): For GIMPLE_COND return early for true/false. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> --- gcc/gimple-fold.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 94d5a1ebbd7..2381a82d2b1 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -6646,12 +6646,19 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree), break; case GIMPLE_COND: { + gcond *gc = as_a <gcond *> (stmt); + /* If the cond is already true/false, just return false. */ + if (gimple_cond_true_p (gc) + || gimple_cond_false_p (gc)) + { + fold_undefer_overflow_warnings (false, stmt, 0); + return false; + } /* Canonicalize operand order. */ - tree lhs = gimple_cond_lhs (stmt); - tree rhs = gimple_cond_rhs (stmt); + tree lhs = gimple_cond_lhs (gc); + tree rhs = gimple_cond_rhs (gc); if (tree_swap_operands_p (lhs, rhs)) { - gcond *gc = as_a <gcond *> (stmt); gimple_cond_set_lhs (gc, rhs); gimple_cond_set_rhs (gc, lhs); gimple_cond_set_code (gc, -- 2.43.0