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

            Bug ID: 126460
           Summary: [17 Regression] wrong code with ((T)A) +- CST -> (T)(A
                    +- CST) fold
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

__attribute__((noipa)) unsigned long long
f (int x)
{
  unsigned int u = (unsigned int) x + 1u;   /* modular, defined */
  int a = (int) u;                          /* GCC: reduction modulo 2^32 */
  return (unsigned long long) a - 1;
}

int
main (void)
{
  if (sizeof (int) == 4 && sizeof (long long) == 8
      && f (__INT_MAX__) != 0xffffffff7fffffffULL)
    __builtin_abort ();
  return 0;
}

aborts at -O1 and above with GCC 17

Reply via email to