https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92712

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For
A*B+A*C -> (B+C)*A
the problematic cases are
A==-1 and B > 0 and C==(max-B)+1 (i.e. when B+C overflows to min)
or A==0 and B < 0 and C<min-B
or A==0 and B > 0 and C>max-B
(last two cases cover when B+C overflows)
For
A*B-A*C -> (B-C)*A
the problematic cases are
A==-1 and B > 0 and C==min+B (i.e. when B-C is min)
or A==0 and B < -1 and C>B-min
or A==0 and B >= 0 and C<B-max
(last two cases cover when B-C overflows)
Again, we perform the operation right now if A is not 0 and not -1 for certain.
I guess we could handle those cases by using something like
check_for_binary_op_overflow, except that for the case where A might be -1 and
plusminus equal to MINUS_EXPR we also need to make sure the result of B-C is
known not to be min.

Reply via email to