[Bug target/48634] New: Missed optimization for use of __builtin_ctzll() and __builtin_clzll
svfuerst at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Apr 15 20:50:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48634
Summary: Missed optimization for use of __builtin_ctzll() and
__builtin_clzll
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: svfuerst@gmail.com
Target: amd64
unsigned long long foo(unsigned long long x)
{
return __builtin_ctzll(x);
}
Compiles into
bsf %rdi,%rax
cltq
retq
at -O3 with 4.6.0
The cltq instruction isn't needed because the bitscan instruction will zero out
the upper 32 bits of rax. Basically, the return value of these intrinsics
should be unsigned long long instead of int on 64 bit machines. The ABI means
that the reverse process of truncating back down to an int costs zero
instructions.
More information about the Gcc-bugs
mailing list