<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 - larger code for std::max({a,b,c}) at -Os than at -O2"
href="https://bugs.llvm.org/show_bug.cgi?id=43305">43305</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>larger code for std::max({a,b,c}) at -Os than at -O2
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hans@chromium.org
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Originally filed in Chromium:
<a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1002750">https://bugs.chromium.org/p/chromium/issues/detail?id=1002750</a>
Consider the following example (see <a href="https://godbolt.org/z/jSMvrK">https://godbolt.org/z/jSMvrK</a>)
#include <algorithm>
int testA(int a, int b, int c) {
return std::max(std::max(a, b), c);
}
int testB(int a, int b, int c) {
return std::max({a, b, c});
}
int main(int argc, char* argv[]) {
return 0;
}
For testA, clang generates two cmov instructions, both at -Os and -O2.
For testB, clang generates the same two cmov instructions at -O2, but at -Os it
doesn't unroll the loop, leading to much larger code.
Could llvm figure out that unrolling the loop is beneficial for size in this
case?
Or would it help if libc++ defined std::max differently? It's unfortunate that
std::max({a, b, c}), which seems more elegant than std::max(std::max(a, b), c),
ends up with much larger code.</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>