https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119509
Bug ID: 119509
Summary: Missed optimization on Arm for comparison of division
equivalent to right shift
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: skrll at netbsd dot org
Target Milestone: ---
#define BIT(n) (1ULL << (n))
#define BITS(m, n) (BIT((m) + 1) - 1) ^ (BIT(n) - 1)
#define LOWEST_SET_BIT(mask) ((((mask) - 1) & (mask)) ^ (mask))
#define SHIFTOUT(x, mask) (((x) & (mask)) / LOWEST_SET_BIT(mask))
unsigned
foo(unsigned val)
{
return SHIFTOUT(val, BITS(23, 8)) != 0;
}
Could be optimized to
tst w0, #0xffff00
cset w0, ne
ret
but currently compiles to
and w0, w0, 16776960
cmp w0, 255
cset w0, hi
ret