https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125783
Bug ID: 125783
Summary: csinc should be prefered pver cinv for `a ? 1 : -1`
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
I noticed these 2 functions have different code generation (at -O2) but they
are exactly the same code:
```
int ff(int a)
{
return a == 0 ? 1 : -1;
}
int ff1(int a)
{
return a != 0 ? -1 : 1;
}
```
The results:
```
ff:
cmp w0, 0
mov w0, 1
csinv w0, w0, wzr, eq
ret
ff1:
cmp w0, 0
mov w0, -1
csinc w0, w0, wzr, ne
ret
```
csinc seems more prefered.