https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123792
Bug ID: 123792
Summary: aarch64: stdc_bit_ceil generates inefficient code
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: wilco at gcc dot gnu.org
Target Milestone: ---
This:
#include <stdbit.h>
long f (unsigned long n)
{
return stdc_bit_ceil (n);
}
generates:
sub x1, x0, #1
mov w2, 63
clz x1, x1
cmp x0, 1
sub w2, w2, w1
mov x1, 2
lsl x1, x1, x2
csinc x0, x1, xzr, hi
ret
The MOV/SUB can be replaced by MVN. The SUB/CMP can be combined into SUBS:
subs x1, x0, #1
clz x1, x1
mvn w2, w1
mov x1, 2
lsl x1, x1, x2
csinc x0, x1, xzr, hi
ret