[llvm-bugs] [Bug 36551] New: Bool vs unsigned result gives very different codegen for bit tests

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 28 09:22:58 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36551

            Bug ID: 36551
           Summary: Bool vs unsigned result gives very different codegen
                    for bit tests
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: craig.topper at gmail.com, efriedma at codeaurora.org,
                    llvm-bugs at lists.llvm.org, spatel+llvm at rotateright.com

https://godbolt.org/g/EFjrMf

Depending on whether we return as a bool or an unsigned, we get quite different
codegen for a !(x & 4) bit-test:

bool foo(int x) {
  return !(x & 4);
}

unsigned bar(int x) {
  return !(x & 4);
}

clang/gcc comes up with 4 different implementations here:

clang -g0 -O3:

define i1 @_Z3fooi(i32) {
  %2 = and i32 %0, 4
  %3 = icmp eq i32 %2, 0
  ret i1 %3
}

define i32 @_Z3bari(i32) {
  %2 = lshr i32 %0, 2
  %3 = and i32 %2, 1
  %4 = xor i32 %3, 1
  ret i32 %4
}

_Z3fooi: # @_Z3fooi
  testb $4, %dil
  sete %al
  retq

_Z3bari: # @_Z3bari
  shrl $2, %edi
  notl %edi
  andl $1, %edi
  movl %edi, %eax
  retq

gcc -g0 -O3:

_Z3fooi:
  movl %edi, %eax
  shrl $2, %eax
  xorl $1, %eax
  andl $1, %eax
  ret

_Z3bari:
  xorl %eax, %eax
  andl $4, %edi
  sete %al
  ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180228/862c89c7/attachment.html>


More information about the llvm-bugs mailing list