<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98433>98433</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong vector select folding on undef values by InstCombine
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bonjune
</td>
</tr>
</table>
<pre>
Transformation of the miscompilation: `select Cond, Y, (shuf_sel X, Y) --> shuf_sel (select Cond, Y, X), Y` (The latter one in the following source code listing)
https://github.com/llvm/llvm-project/blob/7eae9bb856135136cddc4208a2b1546e9db44c9c/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L2616-L2629
Alive2 report: https://alive2.llvm.org/ce/z/EixYHA
```ll
----------------------------------------
define <4 x i8> @fun0(<4 x i8> %val1, i1 %val2) {
entry:
%val3 = shufflevector <4 x i8> { 0, 1, 2, 3 }, <4 x i8> %val1, 0, 5, 2, 3
%val4 = select i1 %val2, <4 x i8> %val1, <4 x i8> %val3
ret <4 x i8> %val4
}
=>
define <4 x i8> @fun0(<4 x i8> %val1, i1 %val2) {
entry:
%sel = select i1 %val2, <4 x i8> %val1, <4 x i8> { 0, poison, 2, 3 }
%val4 = shufflevector <4 x i8> %sel, <4 x i8> %val1, 0, 5, 2, 3
ret <4 x i8> %val4
}
Transformation doesn't verify!
ERROR: Target's return value is more undefined
Example:
<4 x i8> %val1 = < #x00 (0), poison, #x00 (0), undef >
i1 %val2 = undef
Source:
<4 x i8> %val3 = < #x00 (0), poison, #x02 (2), #x03 (3) >
<4 x i8> %val4 = < #x00 (0), poison, #x02 (2), #x03 (3) >
Target:
<4 x i8> %sel = < #x00 (0), poison, #x02 (2), #x03 (3) >
<4 x i8> %val4 = < #x00 (0), poison, #x02 (2), #x00 (0) >
Source value: < #x00 (0), poison, #x02 (2), #x03 (3) >
Target value: < #x00 (0), poison, #x02 (2), #x00 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVt1v2zYQ_2voF8IGddSXH_TgxDE2oMCANMDap0ESTzYLijRIyk321w-k5K_M6bK1GGoYtHl3vPvdB49XOye3GrEi2R3J1rN68Dtjq8boL4PGWWPES_Vka-06Y_vaS6Op6ajfIe2la02_lypSCV9RkjOHCltP740WBO7p57AQKN1u6P5wqOinibqk8znhD_TECEI3zn4isBw3OQsyTzukqvYeLTUaqdQRSmeUMl-l3lJnBtsibY1AqqTzUm-DBrYmbDWuO-_3jvAVgQ2BzVb63dAsWtMT2Ch1OP7M99Z8wdYT2DTKNAQ2Bda4bJoyyxOeJTxvhWhTYGUNTZKlOS5Fk6btsr3QI8O5U_Acgc2v2vl70zdS4_XuY_R90e73BPgHyJN8_gHya-QrJQ8I1OLeWB_ife1KHdmLYHxh7JbApg1G_iSweZDPn39ZXeoiORu_So2E-Ts_o7TATmqkhN-n9JnKMqSSpKwbNCNQXpMhO9QqCUmUybSDUACkuBuVofb2JbgRd3SS4ZTwdayPTuEBW2_sK3vFHWVBbdQNYeGUFOtYcm8giPLZWf7aZDqaHMvwEuzbCm_QT0ot-lv8dMpAsZ7-8DXhD_9PXONN-z4fj1HfG-mMfhX6W-H8RgYjoP-Sr3eG9lXjEgadJlB4ekAruxcCyeWdeHh8_O0x3Kun2m7REyhcMDRYTQ-1GpBKR3tjkQ56zJO4Ov1c93uFp3jfcikGhPDQEvkziw2NTQ3uHM6_86I9eiqSc9aivsi9RPIx9sBvAeHvBwKBBxMvUnig8FhpR0S3UvGjTYwJHTPzlmvH8v55PTtJn02M6RpLLL6iPwz8GK3v1nwD84R86Pv6qsUw2hprQ2vxV1fPHQUSKvU_iDDa1VKhmHsTXuEDvi04vYhorbHu1cM2ExUXS76sZ1glBbC8KJI0ne2qpC5SUTQlJCCKUkDRNKJoCybKfMnSopnJChikrEgSlmUA6aJjaZ43TQrQlZ1gGUkZ9rVUp7d2Jp0bsFqWKeczVTeoXJynADR-pZFJAMJ4Zas4XTTD1pGUhQnFnbV46RVWv1ujt3Tql1Oj7owSYbwxemoGMaeONi_0YoiYDVZV_3q-ifDCcDLCP1TwVwAAAP__lCu9Aw">