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

            Bug ID: 49552
           Summary: switch over select is not optimized
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

inline int test(char a, char b)
{
#ifndef NO_SELECT
    return a < b ? -1 : a > b ? 1 : 0;
#else
    if (a < b) return -1;
    if (a > b) return 1;
    return 0;
#endif
}

void fl();
void fe();
void fg();

void foo(char a, char b)
{
    switch (test(a, b)) {
    case -1: return fl();
    case 0: return fe();
    case 1: return fg();
    }
}

---
; -DNO_SELECT
foo(char, char):
        cmp     dil, sil
        jge     .LBB0_1
        jmp     fl()
.LBB0_1:
        jle     .LBB0_4
        jmp     fg()
.LBB0_4:
        jmp     fe()
;
foo(char, char):
        xor     ecx, ecx
        cmp     dil, sil
        setg    cl
        mov     eax, -1
        cmovge  eax, ecx
        cmp     eax, 1
        je      .LBB0_5
        test    eax, eax
        je      .LBB0_4
        cmp     eax, -1
        jne     .LBB0_6
        jmp     fl()
.LBB0_5:
        jmp     fg()
.LBB0_4:
        jmp     fe()
.LBB0_6:
        ret

---

https://godbolt.org/z/e9vjYK

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to