This moves the `(cmp (cond @0 @1 @2) @3)` simplifcation to be after the boolean comparison simplifcations so that we don't end up simplifing into the same thing for a GIMPLE_COND.
gcc/ChangeLog: * match.pd: Move `(cmp (cond @0 @1 @2) @3)` simplifcation after the bool comparison simplifications. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> --- gcc/match.pd | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index ba036e52837..0fe90a6edc4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7759,20 +7759,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (bit_and@2 @0 integer_pow2p@1) @1) (icmp @2 { build_zero_cst (TREE_TYPE (@0)); }))) -#if GIMPLE -/* From fold_binary_op_with_conditional_arg handle the case of - rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the - compares simplify. */ -(for cmp (simple_comparison) - (simplify - (cmp:c (cond @0 @1 @2) @3) - /* Do not move possibly trapping operations into the conditional as this - pessimizes code and causes gimplification issues when applied late. */ - (if (!FLOAT_TYPE_P (TREE_TYPE (@3)) - || !operation_could_trap_p (cmp, true, false, @3)) - (cond @0 (cmp! @1 @3) (cmp! @2 @3))))) -#endif - (for cmp (ge lt) /* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */ /* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */ @@ -8119,6 +8105,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) replace if (x == 0) with tem = ~x; if (tem != 0) which is clearly less optimal and which we'll transform again in forwprop. */ +#if GIMPLE +/* From fold_binary_op_with_conditional_arg handle the case of + rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the + compares simplify. + This should be after the boolean comparison simplification so + that it can remove the outer comparison before appling it to + the inner condtional operands. */ +(for cmp (simple_comparison) + (simplify + (cmp:c (cond @0 @1 @2) @3) + /* Do not move possibly trapping operations into the conditional as this + pessimizes code and causes gimplification issues when applied late. */ + (if (!FLOAT_TYPE_P (TREE_TYPE (@3)) + || !operation_could_trap_p (cmp, true, false, @3)) + (cond @0 (cmp! @1 @3) (cmp! @2 @3))))) +#endif + /* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z where ~Y + 1 == pow2 and Z = ~Y. */ (for cst (VECTOR_CST INTEGER_CST) -- 2.43.0