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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to