[LLVMbugs] [Bug 12251] New: clang produces unnecessary 'and' after loading a bool

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 12 06:42:39 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12251

             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: unassignedclangbugs at nondot.org
        ReportedBy: rafael.espindola at gmail.com
                CC: llvmbugs at 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.



More information about the llvm-bugs mailing list