<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Loop vectorization stops working because of pointer bitcast"
href="https://llvm.org/bugs/show_bug.cgi?id=25139">25139</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Loop vectorization stops working because of pointer bitcast
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</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>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>yyc1992@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15048" name="attach_15048" title="c repro">attachment 15048</a> <a href="attachment.cgi?id=15048&action=edit" title="c repro">[details]</a></span>
c repro
I first noticed this issue in the following julia code
```
fill_simd(A, v) = @inbounds @simd for i in eachindex(A)
A[i] = v[1]
end
```
The loop failed to be vectorized if `v` is a tuple of the same type with the
elements in `A` but successfully vectorize if the two types are different.
The corresponding c repro is
```
void
fill_simd1(float *__restrict__ A, size_t size, const float *__restrict__ v)
{
for (size_t i = 0;i < size;i++) {
A[i] = *v;
}
}
```
When compiling with clang, the vectorization fails for the function above but
succeed if any of the `float` is replaced with `double`.
With llvm debug output in the julia version, it seems that the reason
vectorization fails is that the vectorizer is expecting a `getelementptr`
instruction as the load address but see a `bitcast` instruction instead.
Relavant llvm ir output,
```
%6 = getelementptr inbounds float, float* %A, i64 %i.01.prol
%7 = bitcast float* %6 to i32*
store i32 %3, i32* %7, align 4, !tbaa !1
```
Such instruction doesn't exist when compiling with LLVM 3.6.2 (julia version)
and the vectorization succeed so somehow some llvm passes is inserting it and
this is an regression in 3.7...
The repro scripts can all be found at
<a href="https://github.com/yuyichao/explore/tree/66a6d368aa5e9dbfc44ad15135296bbbe9f26603/julia/simd_fill">https://github.com/yuyichao/explore/tree/66a6d368aa5e9dbfc44ad15135296bbbe9f26603/julia/simd_fill</a>
I'll also attach them to the bug report later (couldn't figure out how to
attach multiple files at once)</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>