<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 - wrong vectorized code generated at -O2 on x86_64-linux-gnu"
href="https://bugs.llvm.org/show_bug.cgi?id=46189">46189</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>wrong vectorized code generated at -O2 on x86_64-linux-gnu
</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>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kazu@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>A recent patch:
<a href="https://github.com/llvm/llvm-project/commit/9fa58d1bf2f83a556c109f701aacfb92e2184c23">https://github.com/llvm/llvm-project/commit/9fa58d1bf2f83a556c109f701aacfb92e2184c23</a>
causes the following testcase to produce an incorrect result:
// $ clang++ -O2 bug.cc (on x86_64-linux-gnu)
#include <utility>
#include <stdio.h>
__attribute__((noinline))
std::pair<std::pair<int, int>, std::pair<int, int>>
foo(const double x, const double y, const double r, const double xr, const
double yr) {
std::pair<int, int> start = std::make_pair(static_cast<int>((x - r) / xr),
static_cast<int>((y - r) / yr));
std::pair<int, int> end = std::make_pair(static_cast<int>((x + r) / xr),
static_cast<int>((y + r) / yr));
return std::make_pair(start, end);
}
int main(void) {
double x = 5.0;
double y = 7.0;
double r = 1.0;
double xr = 2.0;
double yr = 2.0;
// Expect:
// first.first: (5.0-1.0)/2.0 = 2.0
// first.second: (7.0-1.0)/2.0 = 3.0
// second.first: (5.0+1.0)/2.0 = 3.0
// second.second: (7.0+1.0)/2.0 = 4.0
auto a = foo(x, y, r, xr, yr);
printf("foo: %d %d %d %d\n",
a.first.first, a.first.second, a.second.first, a.second.second);
return 0;
}
Without the patch, I get:
$ clang++ -O2 bug.cc && ./a.out
foo: 2 3 3 4
With the patch, I get:
$ clang++ -O2 bug.cc && ./a.out
foo: 2 3 3 1
FWIW, without the patch, `foo` looks like:
movapd %xmm0, %xmm5
subsd %xmm2, %xmm5
addsd %xmm2, %xmm0
unpcklpd %xmm0, %xmm5 # xmm5 = xmm5[0],xmm0[0]
unpcklpd %xmm3, %xmm3 # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm5
cvttpd2dq %xmm5, %xmm0
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
addsd %xmm2, %xmm1
unpcklpd %xmm1, %xmm3 # xmm3 = xmm3[0],xmm1[0]
unpcklpd %xmm4, %xmm4 # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm3
cvttpd2dq %xmm3, %xmm1
unpcklps %xmm1, %xmm0 # xmm0 =
xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movq %xmm0, %rax
pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1]
movq %xmm0, %rdx
retq
With the patch, `foo` looks like:
movapd %xmm0, %xmm5
subsd %xmm2, %xmm5
addsd %xmm2, %xmm0
unpcklpd %xmm0, %xmm5 # xmm5 = xmm5[0],xmm0[0]
unpcklpd %xmm3, %xmm3 # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm5
cvttpd2dq %xmm5, %xmm0
subsd %xmm2, %xmm1
addsd %xmm2, %xmm2
unpcklpd %xmm2, %xmm1 # xmm1 = xmm1[0],xmm2[0]
unpcklpd %xmm4, %xmm4 # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm1
cvttpd2dq %xmm1, %xmm1
unpcklps %xmm1, %xmm0 # xmm0 =
xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movq %xmm0, %rax
pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1]
movq %xmm0, %rdx
retq</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>