[llvm-bugs] [Bug 47438] New: swap goes through memory when it could stay in registers
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Sep 6 07:41:11 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47438
Bug ID: 47438
Summary: swap goes through memory when it could stay in
registers
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: benny.kra at gmail.com
CC: llvm-bugs at lists.llvm.org
Godbolt: https://godbolt.org/z/Yez1Mc
$ cat t.cc
#include <utility>
struct foo {
float x, y, z, w;
};
void bar(foo& a, foo& b) { std::swap(a, b); }
$ gcc-11 -O3 -S -o - t.cc
bar(foo&, foo&):
movups (%rdi), %xmm0
movdqu (%rsi), %xmm1
movups %xmm1, (%rdi)
movups %xmm0, (%rsi)
ret
$ clang-11 -O3 -S -o - t.cc
bar(foo&, foo&): # @bar(foo&, foo&)
movups (%rdi), %xmm0
movaps %xmm0, -24(%rsp)
movups (%rsi), %xmm0
movups %xmm0, (%rdi)
movaps -24(%rsp), %xmm0
movups %xmm0, (%rsi)
retq
The std::swap expands into an alloca and 3 memcpy's.
--
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/20200906/1c954c9e/attachment.html>
More information about the llvm-bugs
mailing list