[Bug middle-end/112600] Failed to optimize saturating addition using __builtin_add_overflow
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Nov 20 09:23:27 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112600
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note we don't have a good middle-end representation for (integer) saturation.
Maybe having variants of .ADD_OVERFLOW and friends specifying an alternate
value (or the value in case the actual value is left unspecified when
overflow occurs) as additional argument would work. So have the first
fold into
<bb 2> :
_8 = .ADD_OVERFLOW (x_6(D), y_7(D), -1u);
_1 = REALPART_EXPR (_8);
return _1;
of course that defers the code-generation problem to RTL expansion and
would require to pattern match
res = x + y;
res |= -(res < x);
to the same for canonicalization purposes. I would expect that some
targets implement saturating integer arithmetic (not sure about
multiplication or division though).
More information about the Gcc-bugs
mailing list