https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117169
Bug ID: 117169
Summary: Missed opportunity to combine sign and bitmask tests
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: rsandifo at gcc dot gnu.org
Target Milestone: ---
Target: aarch64*-*-*
int f1(int x) { return x < 0 || x & 3; }
on aarch64 produces:
f1:
tbnz w0, #31, .L3
tst x0, 3
cset w0, ne
ret
.L3:
mov w0, 1
ret
But this could be a single TST. Clang produces:
f1:
tst w0, #0x80000003
cset w0, ne
ret
GCC does produce single bitmask tests for non-sign tests, such as:
int f2(int x) { return x & 0x100 || x & 3; }
but of course:
int f3(int x) { return x & 0x80000000 || x & 3; }
is canonicalised to the original form.