https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122390
Bug ID: 122390
Summary: sbcs should be used instead of sbc/cmp
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
Take:
```
int f(int);
int g(int);
int f1(unsigned a, unsigned b)
{
unsigned t = a < b;
int tt = a - t;
if (tt > 0)
return f(tt);
return g(tt);
}
```
GCC currently produces:
```
f1:
cmp w0, w1
sbc w0, w0, wzr
cmp w0, 0
bgt .L4
b g
.L4:
b f
```
The sbc/cmp here should be able to combine into sbcs I think.
```
Trying 12 -> 15:
12: r104:SI=r106:SI-ltu(cc:CC,0)
REG_DEAD cc:CC
REG_DEAD r106:SI
15: cc:CC=cmp(r104:SI,0)
Failed to match this instruction:
(parallel [
(set (reg:CC 66 cc)
(compare:CC (minus:SI (reg/v:SI 106 [ a ])
(ltu:SI (reg:CC 66 cc)
(const_int 0 [0])))
(const_int 0 [0])))
(set (reg/v:SI 104 [ tt ])
(minus:SI (reg/v:SI 106 [ a ])
(ltu:SI (reg:CC 66 cc)
(const_int 0 [0]))))
])
Failed to match this instruction:
(parallel [
(set (reg:CC 66 cc)
(compare:CC (minus:SI (reg/v:SI 106 [ a ])
(ltu:SI (reg:CC 66 cc)
(const_int 0 [0])))
(const_int 0 [0])))
(set (reg/v:SI 104 [ tt ])
(minus:SI (reg/v:SI 106 [ a ])
(ltu:SI (reg:CC 66 cc)
(const_int 0 [0]))))
])
```