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

            Bug ID: 126503
           Summary: Wrong code with signed bitint
           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
                CC: jakub at redhat dot com
  Target Milestone: ---

__attribute__((noipa)) unsigned _BitInt(400)
neg (_BitInt(257) a)
{
  return (unsigned _BitInt(400)) (-a);
}

__attribute__((noipa)) unsigned _BitInt(300)
addm1 (_BitInt(7) a, unsigned _BitInt(17) b)
{
  _BitInt(257) x = (_BitInt(257)) a + -1;
  return ~((unsigned _BitInt(300)) x ^ (unsigned _BitInt(300)) b);
}

int
main (void)
{
  /* -(-1) == 1, so bits 257..399 of the widened result must be 0.  */
  unsigned _BitInt(400) r = neg (-1wb);
  if ((unsigned long long) r != 1
      || (unsigned long long) (r >> 256) != 0
      || (unsigned long long) (r >> 320) != 0)
    __builtin_abort ();

  /* x == 0, so ~(0 ^ 3) has bits 256..299 all set.  */
  unsigned _BitInt(300) s = addm1 (1wb, 3uwb);
  if ((unsigned long long) (s >> 256) != 0xfffffffffffULL)
    __builtin_abort ();
  return 0;
}

on aarch64 aborts with optimisation, but doesn't with -O0

Reply via email to