<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113866>113866</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong folding of `select` and `shufflevector` (commutativity check)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bongjunj
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blob/5d4a0d54b5269bad1410e6db957836fe98634069/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L2618-L2623
Alive2 report: https://alive2.llvm.org/ce/z/BnWdZy
```llvm
----------------------------------------
define <4 x i8> @sel_shuf_commute3.2(<4 x i8> %y, i1 %cmp) {
#0:
%blend = shufflevector <4 x i8> { 0, 0, 0, 0 }, <4 x i8> %y, 0, 5, 2, 3
%r = select i1 %cmp, <4 x i8> %y, <4 x i8> %blend
ret <4 x i8> %r
}
=>
define <4 x i8> @sel_shuf_commute3.2(<4 x i8> %y, i1 %cmp) {
#0:
%sel = select i1 %cmp, <4 x i8> %y, <4 x i8> { 0, poison, 0, 0 }
%r = shufflevector <4 x i8> %sel, <4 x i8> %y, 0, 5, 2, 3
ret <4 x i8> %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<4 x i8> %y = < #x00 (0), #x00 (0), undef, #xff (255, -1) >
i1 %cmp = undef
Source:
<4 x i8> %blend = < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >
<4 x i8> %r = < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >
Target:
<4 x i8> %sel = < #x00 (0), poison, #x00 (0), #x00 (0) >
<4 x i8> %r = < #x00 (0), #x00 (0), #x02 (2), #x00 (0) >
Source value: < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >
Target value: < #x00 (0), #x00 (0), #x02 (2), #x00 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2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