So I stumbled across fold_cond_expr_cond and traced it back to pre-GIMPLE and pre-fold_XXX times. It "folds" all conditions in a function (but only if they fold to always true/false). It does this after CFG construction but before cfg-cleanup. It does that to allow cfg-cleanup to be less expensive - but that's all no longer true as cfg-cleanup basically does the very same "folding" as fold_cond_expr_cond.
Then we have the other caller from tree_function_versioning which folds all copied stmts anyway. And fold_stmt does sth similar (but doesn't throw away non-true/false results). It just restricts itself a bit too much, so I removed the redundant check. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2015-07-23 Richard Biener <rguent...@suse.de> * gimple-fold.c (fold_gimple_cond): Do not require folding results to pass valid_gimple_rhs_p. * tree-cfg.h (fold_cond_expr_cond): Remove. * tree-cfg.c (fold_cond_expr_cond): Likewise. (make_edges): Do not call it. * tree-inline.c (tree_function_versioning): Likewise. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 226091) +++ gcc/gimple-fold.c (working copy) @@ -546,7 +546,7 @@ fold_gimple_cond (gcond *stmt) if (result) { STRIP_USELESS_TYPE_CONVERSION (result); - if (is_gimple_condexpr (result) && valid_gimple_rhs_p (result)) + if (is_gimple_condexpr (result)) { gimple_cond_set_condition_from_tree (stmt, result); return true; Index: gcc/tree-cfg.h =================================================================== --- gcc/tree-cfg.h (revision 226091) +++ gcc/tree-cfg.h (working copy) @@ -31,7 +31,6 @@ extern void gt_pch_nx (edge_def *e, gt_p extern void init_empty_tree_cfg_for_function (struct function *); extern void init_empty_tree_cfg (void); -extern void fold_cond_expr_cond (void); extern void start_recording_case_labels (void); extern void end_recording_case_labels (void); extern basic_block label_to_block_fn (struct function *, tree); Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 226091) +++ gcc/tree-cfg.c (working copy) @@ -606,48 +606,6 @@ create_bb (void *h, void *e, basic_block Edge creation ---------------------------------------------------------------------------*/ -/* Fold COND_EXPR_COND of each COND_EXPR. */ - -void -fold_cond_expr_cond (void) -{ - basic_block bb; - - FOR_EACH_BB_FN (bb, cfun) - { - gimple stmt = last_stmt (bb); - - if (stmt && gimple_code (stmt) == GIMPLE_COND) - { - gcond *cond_stmt = as_a <gcond *> (stmt); - location_t loc = gimple_location (stmt); - tree cond; - bool zerop, onep; - - fold_defer_overflow_warnings (); - cond = fold_binary_loc (loc, gimple_cond_code (cond_stmt), - boolean_type_node, - gimple_cond_lhs (cond_stmt), - gimple_cond_rhs (cond_stmt)); - if (cond) - { - zerop = integer_zerop (cond); - onep = integer_onep (cond); - } - else - zerop = onep = false; - - fold_undefer_overflow_warnings (zerop || onep, - stmt, - WARN_STRICT_OVERFLOW_CONDITIONAL); - if (zerop) - gimple_cond_make_false (cond_stmt); - else if (onep) - gimple_cond_make_true (cond_stmt); - } - } -} - /* If basic block BB has an abnormal edge to a basic block containing IFN_ABNORMAL_DISPATCHER internal call, return that the dispatcher's basic block, otherwise return NULL. */ @@ -1000,9 +958,6 @@ make_edges (void) XDELETE (bb_to_omp_idx); free_omp_regions (); - - /* Fold COND_EXPR_COND of each COND_EXPR. */ - fold_cond_expr_cond (); } /* Add SEQ after GSI. Start new bb after GSI, and created further bbs as Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 226091) +++ gcc/tree-inline.c (working copy) @@ -5847,7 +5847,6 @@ tree_function_versioning (tree old_decl, fold_marked_statements (0, id.statements_to_fold); delete id.statements_to_fold; - fold_cond_expr_cond (); delete_unreachable_blocks_update_callgraph (&id); if (id.dst_node->definition) cgraph_edge::rebuild_references ();