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

            Bug ID: 38003
           Summary: Fold AND+CMP to CMP
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Hello,

bool sw1(int x) {
    switch(x) {
        case 2:
        case 5:
        case 6:
        case 31:
            return true;

        default:
            return false;
    }
}

Clang -03
sw1(int): 
  add edi, -2                 // why?
  cmp edi, 29                 // fold add + cmp to cmp edi, 31
  ja .LBB0_2
  mov eax, 536870937
  mov ecx, edi
  shr eax, cl
  and eax, 1
  ret
.LBB0_2:
  xor eax, eax
  ret


GCC 8.1 emits:
sw1(int):
  xor eax, eax
  cmp edi, 31
  ja .L1
  mov eax, 1
  mov ecx, edi
  sal rax, cl
  test eax, 2147483752
  setne al
.L1:
  ret

ICC 18  (more jumps, worse code?):
sw1(int):
  cmp edi, 64
  jae ..B1.4 
  mov rax, 0x080000068 
  bt rax, rdi 
  jnc ..B1.4 
  mov eax, 1
  ret 
..B1.4: 
  xor eax, eax
  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