[LLVMbugs] [Bug 8730] New: Missed optimization in passing bools

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Dec 2 16:43:50 PST 2010


           Summary: Missed optimization in passing bools
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: nicholas at mxc.ca, llvmbugs at cs.uiuc.edu

$ cat missed_opt.cc
void called(bool b);

void wrapper(bool* b) {
$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
$ g++ -S -O2 missed_opt.cc -o -
        .cfi_personality 0x3,__gxx_personality_v0
        movzbl  (%rdi), %edi
        jmp     _Z6calledb
$ clang++ -S -O2 missed_opt.cc -o -
_Z7wrapperPb:                           # @_Z7wrapperPb
# BB#0:                                 # %entry
        pushq   %rbp
        movq    %rsp, %rbp
        movb    (%rdi), %al
        andb    $1, %al
        movzbl  %al, %edi
        popq    %rbp
        jmp     _Z6calledb              # TAILCALL
$ clang++ -S -emit-llvm -O2 missed_opt.cc -o -
target datalayout =
target triple = "x86_64-unknown-linux-gnu"

define void @_Z7wrapperPb(i8* nocapture %b) {
  %tmp1 = load i8* %b, align 1, !tbaa !0
  %tmp = and i8 %tmp1, 1
  %tobool = icmp ne i8 %tmp, 0
  tail call void @_Z6calledb(i1 zeroext %tobool)
  ret void

declare void @_Z6calledb(i1 zeroext)

The extra 'and' instruction seems to show up any time a bool is loaded from
memory. Nick suggests fixing it by bitcasting to i1* before doing the load.

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