[llvm-bugs] [Bug 49909] New: std::clamp generates suboptimal assembly for primitive types
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 9 13:06:06 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=49909
Bug ID: 49909
Summary: std::clamp generates suboptimal assembly for primitive
types
Product: libc++
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: vittorio.romeo at outlook.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
`std::clamp` generates poor assembly compared to hand-written counterpart for
primitive types like `float`, even with `-Ofast -ffast-math`:
stdclamp(float, float, float): # @stdclamp(float,
float, float)
movss dword ptr [rsp - 4], xmm0
movss dword ptr [rsp - 8], xmm1
movss dword ptr [rsp - 12], xmm2
ucomiss xmm2, xmm0
lea rax, [rsp - 12]
lea rcx, [rsp - 4]
cmovb rcx, rax
ucomiss xmm0, xmm1
lea rax, [rsp - 8]
cmovae rax, rcx
movss xmm0, dword ptr [rax] # xmm0 = mem[0],zero,zero,zero
ret
myclamp(float, float, float): # @myclamp(float, float,
float)
maxss xmm0, xmm1
minss xmm0, xmm2
ret
Live example:
https://godbolt.org/z/5oxvocevK
More information on:
https://secret.club/2021/04/09/std-clamp.html
--
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/20210409/0478cc41/attachment.html>
More information about the llvm-bugs
mailing list