<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 - [x86] horizontal op codegen miscompile"
href="https://bugs.llvm.org/show_bug.cgi?id=40243">40243</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[x86] horizontal op codegen miscompile
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>#include <immintrin.h>
#include <stdio.h>
#include <stdalign.h> // C11 defines _Alignas(). This header defines
alignas()
void print(__m256 in) {
alignas(32) float v[8];
_mm256_store_ps(v, in);
printf("element 4: %.1f\n", v[4]);
printf("element 7: %.1f\n", v[7]);
}
__m256 hadd(__m256 a, __m256 b) {
float r4 = a[4] + a[5];
float r7 = b[6] + b[7];
__m256 r = (__m256){ a[0], a[2], b[0], b[2], r4, a[6], b[4], r7 };
return __builtin_shufflevector(r, a, -1, -1, -1, -1, 4, -1, -1, 7);
}
int main() {
__m256 a = _mm256_set_ps(7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0);
__m256 b = _mm256_set_ps(15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0);
print(hadd(a, b));
return 0;
}
-----------------------------------------------------------------------------
$ clang checkhadd.c -mavx -O0 ; ./a.out
element 4: 9.0
element 7: 29.0
$ clang checkhadd.c -mavx -O1 ; ./a.out
element 4: 9.0
element 7: 13.0 <--- 14.0 + 15.0 ???
------------------------------------------------------------------------------
I think this is a long-standing bug in LowerToHorizontalOp() -- it's visible on
the shipping macOS version of clang.
There's probably a small fix that could correct this, but given that we're also
missing horizontal patterns completely and only partially matching/optimizing
other patterns, I wonder if we should start over on that function.</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>