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

            Bug ID: 116753
           Summary: [regression from GCC 12.4] GCC trunk (-O3) can't fold
                    a loop into a constant
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dccitaliano at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/xGh9vY57b

```
long patatino() {
    long x = 0;
    for (int i = 0; i < 5; ++i) {
        while (x < 10) {
            if (x % 2 == 0) {
                x += 2;
            } else {
                x += 1;
            }
            // Dead while loop
            while ((x > 20) && (i % 3 == 0) && (x % 5 == 0)) {
                x -= 5;
            }
            // Dead while loop
            while ((x < -5) && (i % 2 == 0) && (x % 3 == 0)) {
                x += 3;
            }
        }
    }
    return x;
}
```

GCC trunk emits:
patatino():
        mov     eax, 2
.L2:
        add     rax, 2
        cmp     rax, 9
        jle     .L2
        ret

GCC 12.4 emits:
patatino():
        mov     eax, 10
        ret

Reply via email to