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

            Bug ID: 124848
           Summary: `x==0 ? 0 : x-1` should be optimized to subs/cinc
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int f(int x) { return x==0 ? 0 : x-1; }
```

This should be optimized to:
```
        subs    w0, w0, #1
        cinc    w0, w0, cc
        ret
```

but current GCC produces:
```
        cmp     w0, 0
        cset    w1, ne
        sub     w0, w0, w1
```


Note x86_64 gives (ignore the move):
```
        cmp     edi, 1
        mov     eax, edi
        adc     eax, -1
```
Which was done in GCC 8.

Reply via email to