[llvm-bugs] [Bug 43671] New: Use cmp+sbb instead of test+set for select of constants
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Oct 14 03:32:11 PDT 2019
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: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191014/9cfb5eb9/attachment.html>
More information about the llvm-bugs
mailing list