Bug #: 12251
Summary: clang produces unnecessary 'and' after loading a bool
Product: clang
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
AssignedTo: unassigne...@nondot.org
ReportedBy: rafael.e...@gmail.com
CC: llvm...@cs.uiuc.edu
Classification: Unclassified
The X86-64 abi says:
Booleans, when stored in a memory object, are stored as single byte objects the
value of which is always 0 (false) or 1 (true).
For the function
bool foo(bool *x) {
return *x;
}
clang produces this IL (after optimizations):
define zeroext i1 @_Z3fooPb(i8* nocapture %x) nounwind uwtable readonly ssp {
entry:
%0 = load i8* %x, align 1, !tbaa !0
%1 = and i8 %0, 1
%tobool = icmp ne i8 %1, 0
ret i1 %tobool
}
which ends up producing:
movb (%rdi), %al
andb $1, %al
ret
Producing instead
define zeroext i1 @_Z3fooPb2(i8* nocapture %x) nounwind uwtable readonly ssp {
entry:
%x2 = bitcast i8* %x to i1*
%tmp0 = load i1* %x2, align 1
ret i1 %tmp0
}
would result in
movb (%rdi), %al
ret
Apple's gcc 4.2 produces
movzbl (%rdi), %eax
ret
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
LLVM...@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs
Rafael Ávila de Espíndola <rafael.e...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #12 from Rafael Ávila de Espíndola <rafael.e...@gmail.com> 2012-03-26 10:32:19 CDT ---
The 'and' is gone, but we are still not as efficient as gcc. I opened pr12360
to track the missing improvements.