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

            Bug ID: 43671
           Summary: Use cmp+sbb instead of test+set for select of
                    constants
           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], [email protected],
                    [email protected], [email protected]

Motivation cases:
int foo(unsigned a) {
    return a ? -1 : 1;
}

unsigned foo(unsigned a) {
    return a ? 10 : 8;
}

Seems like, for some cases x ? A : B the GCC's code:

foo(unsigned int):
        cmp     edi, 1
        sbb     eax, eax
        and     eax, -2
        add     eax, 10
        ret

Block RThroughput: 1.2

is better than Clang trunk's:
foo(unsigned int):                                
        xor     eax, eax
        test    edi, edi
        setne   al
        add     eax, eax
        add     eax, 8
        ret

Block RThroughput: 1.3

I dont know the generalized rule here, but it seems like cmp+sbb is better when
A - B (or B - A) is 2, but also cmp+sbb is better in this case:
int foo(unsigned a) {
    return a ? -1 : -9;
}

If we ignore cases when A or B is 0/1 (some other transformation kicks in;
codegen is good), it seems like cmp+sbb codegen is never worse than current
test+set+add codegen.


Current codegen: https://godbolt.org/z/GSa0wc

-- 
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