[Bug middle-end/122004] x86 optimization: (x > INT_MAX - c) can utilize overflow flag to save code size

law at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 8 22:09:26 GMT 2025


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

--- Comment #2 from Jeffrey A. Law <law at gcc dot gnu.org> ---
ITSM that if something like a .SUB_OVERFLOW's result isn't used, then we could
optimize away the .SUB_OVERFLOW and just emit the comparison necessary to check
for overflow.

  _3 = .SUB_OVERFLOW (x_2(D), -127);
  _1 = IMAGPART_EXPR <_3>;
  _4 = (_Bool) _1;
  return _4;

So just _1 = -128 < x_2 and drop the assignment to _3 entirely. Or somehing
along those lines.   It's kind of like throwing away part of divmod.  So there
may also be something we can do over in RTL, though it's likely harder there.


More information about the Gcc-bugs mailing list