[LLVMbugs] [Bug 2005] New: Bad codegen on x86 with _Bool
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Sun Feb 10 01:04:37 PST 2008
http://llvm.org/bugs/show_bug.cgi?id=2005
Summary: Bad codegen on x86 with _Bool
Product: new-bugs
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sharparrow1 at yahoo.com
CC: llvmbugs at cs.uiuc.edu
Take the following C method:
_Bool a(_Bool a, _Bool b, _Bool c) {return a ? b : c;}
clang compiles it to the following (except that clang screws up the attributes
at the moment):
define i1 @a(i1 zeroext %a, i1 zeroext %b, i1 zeroext %c) nounwind zeroext {
entry:
%retval = select i1 %a, i1 %b, i1 %c
ret i1 %retval
}
This gets compiled to the following x86 code:
movb 12(%esp), %al
movzbw %al, %ax
movb 8(%esp), %cl
movzbw %cl, %cx
movb 4(%esp), %dl
testb %dl, %dl
cmovne %cx, %ax
andl $1, %eax
ret
This is correct, but it's about twice as long as it needs to be.
I'd expect something like the following (untested):
movzbl 12(%esp), %eax
movzbl 8(%esp), %ecx
cmpl $0, 4(%esp)
cmovne %ecx, %eax
ret
llvm-gcc compiles the C code to something a bit different:
define i8 @a(i8 zeroext %a, i8 zeroext %b, i8 zeroext %c) zeroext {
entry:
%tmp3 = icmp eq i8 %a, 0 ; <i1> [#uses=1]
%iftmp.16.0.in.in = select i1 %tmp3, i8 %c, i8 %b
%iftmp.16.0.in = icmp ne i8 %iftmp.16.0.in.in, 0
%retval1819 = zext i1 %iftmp.16.0.in to i8
ret i8 %retval1819
}
Which gets compiled to the following x86:
movzbw 12(%esp), %ax
movzbw 8(%esp), %cx
cmpb $0, 4(%esp)
cmove %ax, %cx
testb %cl, %cl
setne %al
movzbl %al, %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.
More information about the llvm-bugs
mailing list