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

            Bug ID: 39116
           Summary: Better switch lowering using and + sete
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

bool switch_ob_one_two_cases(int x) {
    switch(x) {
        case 0:
        case 2:
            return true;

        default:
            return false;
    }
}

Clang:
switch_ob_one_two_cases(int): 
        mov     al, 1
        or      edi, 2
        cmp     edi, 2
        jne     .LBB0_1
        ret
.LBB0_1:
        xor     eax, eax
        ret

GCC can emit nice code:
switch_ob_one_two_cases(int):
  and edi, -3
  sete al
  ret

bool switch_ob_one_two_cases2(int x) {
    switch(x) {
        case 7:
        case 11:
            return true;

        default:
            return false;
    }
}

GCC:
switch_ob_one_two_cases2(int):
  sub edi, 7
  and edi, -5
  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