The problem here is that tree-if-conv.c produces COND_EXPR instead of the MAX/MIN EXPRs. When I added the expansion from COND_EXPR to conditional moves, I assumes that the expressions which should have been converted into MAX_EXPR/MIN_EXPR have already happened.
This fixes the problem by having tree-if-conv fold the expression so the MIN_EXPR/MAX_EXPR appears in the IR rather than COND_EXPR and the expansion happens correctly to the min/max rtl rather than just through the conditional move ones. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * tree-if-conv.c (predicate_scalar_phi): Call fold_build3 instead of build3. (predicate_mem_writes): Likewise.
Index: tree-if-conv.c =================================================================== --- tree-if-conv.c (revision 187683) +++ tree-if-conv.c (working copy) @@ -1313,8 +1313,8 @@ predicate_scalar_phi (gimple phi, tree c || bb_postdominates_preds (bb)); /* Build new RHS using selected condition and arguments. */ - rhs = build3 (COND_EXPR, TREE_TYPE (res), - unshare_expr (cond), arg_0, arg_1); + rhs = fold_build3 (COND_EXPR, TREE_TYPE (res), + unshare_expr (cond), arg_0, arg_1); } new_stmt = gimple_build_assign (res, rhs); @@ -1574,7 +1574,7 @@ predicate_mem_writes (loop_p loop) cond = force_gimple_operand_gsi_1 (&gsi, unshare_expr (cond), is_gimple_condexpr, NULL_TREE, true, GSI_SAME_STMT); - rhs = build3 (COND_EXPR, type, unshare_expr (cond), rhs, lhs); + rhs = fold_build3 (COND_EXPR, type, unshare_expr (cond), rhs, lhs); gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi)); update_stmt (stmt); }