[Bug tree-optimization/126874] New: [17 Regression] wrong code at -O2

xxs_chy at outlook dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126874

            Bug ID: 126874
           Summary: [17 Regression] wrong code at -O2
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Reproducer: https://godbolt.org/z/fP5xMsjGP
Reduced case:
#include <stdint.h>
#include <stdio.h>
uint64_t g1, __chk, g23, g14 = 9;
int main()
{
    _Bool c0, c4;
    uint16_t ov8;
    c0 = c4 = g1 = g14;
    __builtin_add_overflow(0, g23, &ov8);
    if (c0) goto lbl_b8;
lbl_b8:
    if (!c4) __builtin_unreachable();
    c4 = 0 >= (int64_t)g1;
    if (ov8) goto lbl_b8;
    __chk = g1;
    printf("checksum=0x%016llx\n", (unsigned long long)__chk);
}

This case outputs checksum=0x0000000000000000 at -O2, and outputs
checksum=0x0000000000000009 at -O0.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.