<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 - Incorrect codegen for #pragma omp simd loop at -O1"
href="https://bugs.llvm.org/show_bug.cgi?id=48625">48625</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect codegen for #pragma omp simd loop at -O1
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>damatthews@smu.edu
</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>The following program leads to incorrect codegen on x86-64 when compiled with
'-fopenmp-simd -O1': only every 4th (SSE) or 8th (AVX) element is summed for
large n. Changing the optimization level or enabling either FIX1 or FIX2 in the
code avoids the problem. The problem occurs in both C and C++ mode and
seemingly for any x86-64 uarch. Example of incorrect ASM:
<a href="https://godbolt.org/z/17n8bP">https://godbolt.org/z/17n8bP</a>.
```C
#ifdef __cplusplus
#define restrict __restrict
#endif
#define FIX1 0
#define FIX2 0
void sum(int n, const float* A,
#if FIX1
float* restrict value)
#else
float* value_)
#endif
{
#if !FIX1 && !FIX2
float* restrict value = (float* restrict)value_;
#endif
#if FIX2
float tmp = *value_;
float* value = &tmp;
#endif
#pragma omp simd
for (int i = 0;i < n;i++) *value += A[i];
#if FIX2
*value_ = tmp;
#endif
}
```</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>