[llvm-bugs] [Bug 43658] New: Improve codegen for std::midpoint
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Oct 12 16:05:43 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43658
Bug ID: 43658
Summary: Improve codegen for std::midpoint
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
When one argument is a known constant value, gcc produces better code.
int foo(int a) {
return std::midpoint(a,100);
}
Clang trunk -O3
foo(int): # @foo(int)
cmp edi, 100
mov ecx, 100
mov eax, edi
cmovg eax, ecx
cmp edi, 99
cmovg ecx, edi
sub ecx, eax
shr ecx
mov eax, ecx
neg eax
cmp edi, 100
cmovle eax, ecx
add eax, edi
ret
Block RThroughput: 2.7
GCC -O3
foo(int):
mov edx, 100
cmp edi, 101
mov eax, edx
cmovl edx, edi
setl cl
cmovge eax, edi
movzx ecx, cl
lea ecx, [rcx-1+rcx]
sub eax, edx
shr eax
imul eax, ecx
add eax, edi
ret
Block RThroughput: 2.5
https://godbolt.org/z/F6PE2w
--
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/20191012/29a5793e/attachment.html>
More information about the llvm-bugs
mailing list