[Bug tree-optimization/96272] New: Failure to optimize overflow check

gabravier at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jul 21 17:36:00 GMT 2020


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

            Bug ID: 96272
           Summary: Failure to optimize overflow check
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

static inline unsigned f(unsigned a, unsigned b)
{
    if (b > UINT_MAX - a)
        return UINT_MAX;

    return a + b;
}

With -O3, LLVM outputs this:

f(unsigned int, unsigned int):
  add edi, esi
  mov eax, -1
  cmovae eax, edi
  ret

GCC outputs this:

f(unsigned int, unsigned int):
  mov eax, edi
  not eax
  add edi, esi
  cmp eax, esi
  mov eax, -1
  cmovnb eax, edi
  ret


More information about the Gcc-bugs mailing list