<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123639>123639</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SLP Vectorizer miscompilation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:SLPVectorizer
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aleks-tmb
</td>
</tr>
</table>
<pre>
During our local testing, we identified a miscompilation where the SLP Vectorizer appears to be the cause. Here is the reproducer we managed to prepare:
https://godbolt.org/z/9nePcq7Go
The issue can be demonstrated using the `lli` tool. Unfortunately, I cannot use alive2 due to unknown libcall errors, such as @llvm.vector.insert.v32i32.v16i32 not being recognized by alive2
```
$ bin/opt -passes=slp-vectorizer -mattr=+avx2 src.ll -S > tgt.ll
$ bin/lli src.ll
Result: -256
$ bin/lli tgt.ll
Result: -272
```
The pseudocode represented by the IR is
```
t = 0
for (i = 0; i < 16; i++) {
s -= (t + i)
t = i
}
```
```
s -= (1 + 0) + (2 + 1) + (3 + 2) + (4 + 3) + ... + (14 + 15) + (15 + 16)
s = -256
```
This indicates that the SLP Vectorizer pass produces incorrect IR.
The issue became reproducible after patch `[SLP] Match poison as instruction with the same opcode` made by @alexey-bataev
https://github.com/llvm/llvm-project/commit/b8703369daf777706196ff914c0376c27adde3cf
I'll provide more details on how the patch affects the issue as soon as I receive them.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVM1u4zYQfhr6MrAgDS0pOuhgr-s2wBYIkm3vFDW22KVIlaSUTZ6-IOU0TraXAgI0GM7PNz_fCO_VxRC1rDyw8rgRcxisa4Wm734bxm7T2f6lPc5OmQvY2YG2UmgI5IMyF4Zf4JlA9WSCOivqQcCovLTjpLQIyhp4HsgRhIHg6esD_EkyWKdeyYGYJhLOQ7DQrQZSzJ4y-C06KJ9UjiZn-1mSi3lGYcSF-ugyOZqEI8b3LN8PIUw-inhie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