<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - missed optimization to use MOVS to copy arrays"
href="https://bugs.llvm.org/show_bug.cgi?id=47794">47794</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>missed optimization to use MOVS to copy arrays
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>enhex0@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>For example the following code generates `MOVSQ` with GCC, and `call memcpy`
with Clang:
<a href="https://godbolt.org/z/15bPh5">https://godbolt.org/z/15bPh5</a>
```
#include <iostream>
#include <array>
#include <random>
using namespace std;
random_device rd;
int main()
{
std::array<char, 512> a;
std::array<char, 512> b;
for(auto& e : a) { // prevent optimizing away
e = rd();
}
for(int i=0; i < a.size(); ++i) { // copy
b[i] = a[i];
}
for(auto const& e : b) { // prevent optimizing away
cout << e;
}
}
```
It seems that using MOVSQ is about 4-5 times faster:
Clang: <a href="https://quick-bench.com/q/LK5SmbOYZc8T-Kvy48jsf1tAL9w">https://quick-bench.com/q/LK5SmbOYZc8T-Kvy48jsf1tAL9w</a>
GCC: <a href="https://quick-bench.com/q/qG8ApWJV7Ad-ghub2of6C_WWMYM">https://quick-bench.com/q/qG8ApWJV7Ad-ghub2of6C_WWMYM</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>