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

            Bug ID: 128585
           Summary: Wrong code with folding x ==/!= (T)(x ==/!= C)
           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: ---

As discussed in
https://gcc.gnu.org/pipermail/gcc-patches/2026-November/738109.html thanks to
Andrea we have a C99 testcase so filing this PR to track the bug fixes and
backports.

struct s1
{
    int s : 1;
};
__attribute__((noipa)) int
f1 (struct s1 a)
{
  struct s1 b;
  struct s1 c = a;
  int t = a.s;
  b.s = (t == -1);
  int t1 = b.s;
  int t2 = c.s;
  return t2 != t1;
}

__attribute__((noipa)) int
f2 (struct s1 a)
{
  struct s1 b;
  struct s1 c = a;
  int t = a.s;
  b.s = (t == -1);
  int t1 = b.s;
  int t2 = c.s;
  return t2 == t1;
}

int
main ()
{
  if (f1 ((struct s1){-1}) != 0
       || f1 ((struct s1){0}) != 0)
    __builtin_abort ();
  if (f2 ((struct s1){-1}) != 1 || f2 ((struct s1){0}) != 1)
    __builtin_abort ();
}

Aborts on aarch64 at -O2 and passes at -O0

Reply via email to