This removes folding of conditions in GIMPLE_CONDs using fold_binary from fold_stmt. All cases appearing during bootstrap and regtest on x86_64-unknown-linux-gnu are now handled by gimple_simplify and match.pd patterns (remember this is just two bare operand cases). I've verified this using the 2nd patch below which passes bootstrap & regtest.
Boostrapped and tested on x86_64-unknown-linux-gnu. [2/2] will do the same for comparisons on the RHS of assignments (note fold_stmt never folded the comparison embedded in RHS [VEC_]COND_EXPRs, only forward_propagate_into_cond does right now). Richard. 2015-07-29 Richard Biener <rguent...@suse.de> * gimple-fold.c (fold_gimple_cond): Remove. (fold_stmt_1): Do not call it. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 226340) +++ gcc/gimple-fold.c (working copy) @@ -529,33 +529,6 @@ fold_gimple_assign (gimple_stmt_iterator return NULL_TREE; } -/* Attempt to fold a conditional statement. Return true if any changes were - made. We only attempt to fold the condition expression, and do not perform - any transformation that would require alteration of the cfg. It is - assumed that the operands have been previously folded. */ - -static bool -fold_gimple_cond (gcond *stmt) -{ - tree result = fold_binary_loc (gimple_location (stmt), - gimple_cond_code (stmt), - boolean_type_node, - gimple_cond_lhs (stmt), - gimple_cond_rhs (stmt)); - - if (result) - { - STRIP_USELESS_TYPE_CONVERSION (result); - if (is_gimple_condexpr (result)) - { - gimple_cond_set_condition_from_tree (stmt, result); - return true; - } - } - - return false; -} - /* Replace a statement at *SI_P with a sequence of statements in STMTS, adjusting the replacement stmts location and virtual operands. @@ -3711,10 +3684,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, break; } - case GIMPLE_COND: - changed |= fold_gimple_cond (as_a <gcond *> (stmt)); - break; - case GIMPLE_CALL: changed |= gimple_fold_call (gsi, inplace); break; Testing patch: Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 226340) +++ gcc/gimple-fold.c (working copy) @@ -548,6 +551,13 @@ fold_gimple_cond (gcond *stmt) STRIP_USELESS_TYPE_CONVERSION (result); if (is_gimple_condexpr (result)) { + /* Folding changes 1 != 0 to 1 thus avoid false changed + reporting if the condition didn't really change. */ + if (is_gimple_val (result) + && gimple_cond_code (stmt) == NE_EXPR + && integer_zerop (gimple_cond_rhs (stmt)) + && operand_equal_p (gimple_cond_lhs (stmt), result, 0)) + return false; gimple_cond_set_condition_from_tree (stmt, result); return true; } @@ -3712,8 +3708,11 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, } case GIMPLE_COND: - changed |= fold_gimple_cond (as_a <gcond *> (stmt)); - break; + { + bool cg = fold_gimple_cond (as_a <gcond *> (stmt)); + gcc_assert (!cg); + break; + } case GIMPLE_CALL: changed |= gimple_fold_call (gsi, inplace);