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

            Bug ID: 128051
           Summary: wrong code at -O1 and above for ((long)(x & -4) &
                    0xFFFFFFFF00000000) == 0 && (x & 1) == 1
           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: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

int cnt;
__attribute__((noipa)) void hit(void) { cnt++; }
__attribute__((noipa)) void f(int x) {
  if (((long)(x & -4) & 0xFFFFFFFF00000000L) == 0 && (x & 1) == 1)
    hit();
}
int main(void) {
  f(-5);
  if (cnt != 0)
    __builtin_abort();
}

godbolt: https://godbolt.org/z/nq6z5qavc

For x = -5, (long)(x & -4) is -8, so the first condition is false and hit()
must not be called. With -O0, or -O1 -fdisable-tree-ifcombine, the program
exits normally; with -O1, -O2, -O3 or -Os it calls hit() and aborts.

Reply via email to