<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64177>64177</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Instcombine] Undef shuffle may lead to unsound transform
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alexey-bataev
</td>
</tr>
</table>
<pre>
Shuffle with undef vector (not poison) and non-poison index leads to unsound transformation
define <3 x i32> @select_and_insert_values(<3 x i32> %a, <3 x i32> %b, <3 x i32> %c) {
%c0 = extractelement <3 x i32> %c, i32 0
%cmp0 = icmp ne i32 %c0, 0
%1 = insertelement <2 x i1> poison, i1 %cmp0, i32 0
%2 = shufflevector <2 x i1> %1, <2 x i1> poison, <2 x i32> zeroinitializer
%3 = shufflevector <3 x i32> %a, <3 x i32> poison, <2 x i32> zeroinitializer
%4 = shufflevector <3 x i32> %b, <3 x i32> poison, <2 x i32> <i32 0, i32 1>
%5 = select <2 x i1> %2, <2 x i32> %3, <2 x i32> %4
%6 = shufflevector <2 x i32> %5, <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
ret <3 x i32> %6
}
https://alive2.llvm.org/ce/z/jUBXvb
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlE1vozwQxz_NcLESOWMI4cChTR6k57yqtLfK4CFxZewIm2zaT7_CJF22Zd8uvIxn_j_PjD3Se320RCVkj5AdEjmEk-tLaehKr6taBkmXpHbqtfxyGtrWEPumw4kNVlHLLtQE1zPAnXWBnZ32zgIWTFrFrLOrycK0VXRlhqTyLDg2WO8Gq1jopfWt6zsZtLPAD8AfpqeiVltiIPaCXZkWCOI_Bin3ZKgJz9KqZ2099eH5Is1AHnD3wRczCbj_qIBZvWhtxk1D_jjRWTRxBuLA6Bp62QQy1JENi5H78ZfxeWx3nqJ1052ZpegQNUfvuedmcou5zBg4MjYj4l7TPdObu_QSEqOQn1p0b8tcaITdcl9Sv5unxN6od9rqoKXRb9TPOGKZ88fS_zsp_RvSQjt_RQKxn4p2q95YgBkum3DxgH2qHC7IYSYWrelMdPubrrwHZJ9l4u1aOKmfUrh94CyXnhaO6fZ2u_LD_JqdQjh7EA-AFWAljb4Qro25dGvXHwGrhgCrN8Dq5enx66VOVClUIQqZULnZFjwt0i3fJacSRZ2R4tTynNJU7ZB2bZ4Xdaa2meSoEl0iR8FzzHGTcb5bb3lKaZ6KYteoos43kHLqpDbv9ER7P1C5TTd5nhhZk_FxQiF22jeuO2szTQ0cewOIYyCIB219aFxXa0vjUnZI-nJcWtXD0UPKjfbB_6AEHUwcff_P4rIDe4rj7dY41snXOL0Wh1cy9Kb8uZJHHU5DvW5cB1jFjU2v1bl3L9QEwCqm5wGrmOH3AAAA__9U5ZHv">