On Fri, Feb 04, 2022 at 10:53:22AM +0100, Eric Botcazou wrote: > > Well, yes, we have to fix it. > > Here's the fix we agreed upon in the audit trail, OK for the mainline? > > PR tree-optimization/104356 > * match.pd (X / bool_range_Y is X): Add guard. > (X / X is one): Likewise. > (X / abs (X) is X < 0 ? -1 : 1): Likewise. > (X / -X is -1): Likewise. > (1 / X -> X == 1): Likewise.
Looks mostly good, just a few nits. > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -401,27 +401,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* X / bool_range_Y is X. */ > (simplify > (div @0 SSA_NAME@1) > - (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1)) > + (if (INTEGRAL_TYPE_P (type) > + && ssa_name_has_boolean_range (@1) > + && !flag_non_call_exceptions) ssa_name_has_boolean_range call is certainly more expensive than !flag_non_call_exceptions check, can you swap those two? > @@ -444,6 +452,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (trunc_div integer_onep@0 @1) > (if (INTEGRAL_TYPE_P (type) > && !integer_zerop (@1) > + && (!flag_non_call_exceptions || tree_expr_nonzero_p (@1)) > && TYPE_PRECISION (type) > 1) And similarly, TYPE_PRECISION (type) > 1 check is very cheap, can it be done before the && !integer_zerop (@1) line? I admit this one is already preexisting, but tree_expr_nonzero_p can be quite expensive. Otherwise LGTM. Jakub