[Bug middle-end/48580] missed optimization: integer overflow checks
jules at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Oct 5 12:44:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48580
jules at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jules at gcc dot gnu.org
--- Comment #12 from jules at gcc dot gnu.org 2011-10-05 12:41:55 UTC ---
I don't much like the idea of using builtins for operations as fundamental as
integer arithmetic. How about this as a straw-man suggestion: adding new
qualifiers for "fat" integers-with-flags, somewhat in the spirit of the
embedded-C fractional/saturating types? So you might have:
int x, y;
void foo (void)
{
_Flagged int res;
res = (_Flagged int) x + y;
if (_Carry (res))
printf ("sum carried\n");
if (_Overflow (res))
printf ("sum overflowed\n");
}
this avoids problems with global state, and allows for the programming style
which (I vaguely get the impression that) people seem to want -- performing a
"normal" integer operation, then querying for carry/overflow flags afterwards.
These types wouldn't be allowed to cross ABI boundaries (although of course you
could use the magic builtins _Carry/_Overflow to extract values to pass to
functions), and "_Overflow" would only be allowed for signed types. You could
also have "_Borrow" for subtraction maybe (whose meaning would be the inverse
of _Carry).
Signalling variants could look like, e.g.:
void bar (void)
{
int res;
res = (_Signalling _Flagged int) x + y;
}
Things would get awkward if you tried to use these new constructs in
more-complicated expressions, I suppose. Anyway, just an idea.
More information about the Gcc-bugs
mailing list