<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58092>58092</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[bug]clang-10 doesn't allow #pragma omp simd in constexpr functions, but gcc-9.3 does.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aerosayan
</td>
</tr>
</table>
<pre>
Hello everyone,
First time reporting a compiler bug, so apologies if this bug has already been reported, or some information is not provided well. Kindly let me know if more information is required.
So, I'm writing some low level optimized code for dense vector operations, and I noticed that clang-10 doesn't compile constexpr functions with `#pragma omp simd` i.e OpenMP SIMD directives in them.
This is wrong.
gcc-9.3 supports them, and that is actually correct, as constexpr functions can be computed both at compile time, and runtime.
My code is little weird, as it is automatically optimized and computed at compile time for vectors with less than 8 elements, but is computed at runtime for large vectors with a simd vectorized for loop.
Here's a function which doesn't compile with clang-10.
I'm humbly requesting for it to be fixed. This kind of optimizations is very important for us.
```c++
constexpr DenseVector operator-() const
{
constexpr Index s = tVectorSize;
constexpr Index l = static_cast<Index>(9);
DenseVector result;
if constexpr(s > 0 and s < l) { result[0] = -mData[0]; }
if constexpr(s > 1 and s < l) { result[1] = -mData[1]; }
if constexpr(s > 2 and s < l) { result[2] = -mData[2]; }
if constexpr(s > 3 and s < l) { result[3] = -mData[3]; }
if constexpr(s > 4 and s < l) { result[4] = -mData[4]; }
if constexpr(s > 5 and s < l) { result[5] = -mData[5]; }
if constexpr(s > 6 and s < l) { result[6] = -mData[6]; }
if constexpr(s > 7 and s < l) { result[7] = -mData[7]; }
if constexpr(s >= l)
{
#pragma omp simd
for(Index i=0; i<tVectorSize; ++i)
{
result[i] = -mData[i];
}
}
return result;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVltuO4jgQhp8m3JRAIYEAF7mYbqY1rVVrV-rV3o5MUkm849hZ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