https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68894
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Doing this in a classical way in phi-opt might end up being slightly convoluted. So I'd propose to try to utilize match-and-simplify by adding (cond (ge @0 @1) (max:s @0 @2) (max:s @1 @2)) -> (max (max @0 @1) @2) kind patterns and from phiopt doing exploded queries of this simplification by seeding the cond expr from the dominating condition plus the PHI operands. res = gimple_simplify (COND_EXPR, build2 /* Ick */ (cond-code, boolean_type, cond-op0, cond-op1), true-phi-arg, false-phi-arg, &seq, follow_single_use_edges); of course you need more than a single pattern or consider swapped ops 2 and 3 (not yet supported). In the end explicit pattern explosion might make a manual implementation in phiopt easier (who knows). /* Ick */ might not actually work so you'd need to build a SSA def for the comparison result. Or implement stmt matching on GIMPLE_PHIs doing that transparently (two-operand with a common controling edge predicate).