<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 - c++14 cause worse codegen than c++1z."
href="https://bugs.llvm.org/show_bug.cgi?id=34196">34196</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>c++14 cause worse codegen than c++1z.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>denis.yaroshevskij@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18988" name="attach_18988" title="code">attachment 18988</a> <a href="attachment.cgi?id=18988&action=edit" title="code">[details]</a></span>
code
Hi.
I was playing with variant implementation and found out that c++1z option
produces a better code than with c++14. Might be worth looking into.
Unfortunately, links to goldbolt currently do not work, so I attach code as
file.
It's not exactly an easy read so quick idea:
for each possible combination of parameters, I instantiate a function. All of
this functions are written in one n-dimentional array, where each dimension
corresponds to an element.
So sum of two variants should be equivalent to:
int sum(const variant<int, char>& x, const variant<char, int>& y) {
using f_type = ...
static const f_type vtable = {
{
[](decltype(x) x, decltype(y) y) -> int {
return get<0>(x) + get<0>(y); },
[](decltype(x) x, decltype(y) y) -> int {
return get<0>(x) + get<1>(y); },
},
{
[](decltype(x) x, decltype(y) y) -> int {
return get<1>(x) + get<0>(y); },
[](decltype(x) x, decltype(y) y) -> int {
return get<1>(x) + get<1>(y); },
}
};
return vtable[x.idx][y.idx](x, y);
}
Compiling with c++1z generates 2 times less instructions than with c++14. This
does not seem right.
Compilation options: -Werror -Wall --std=c++1z -O3 -fno-exceptions -DNDEBUG</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>