<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97730>97730</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong masked merge of vector operands 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>
https://alive2.llvm.org/ce/z/Nws3Yr
```
----------------------------------------
define <4 x i1> @fun0(<4 x i1> %val0, <4 x i1> %val1, <4 x i1> %val2) {
entry:
%val3 = add <4 x i1> %val1, { 1, 1, 1, 1 }
%val4 = xor <4 x i1> { 0, undef, undef, 1 }, %val0
%val5 = and <4 x i1> %val4, %val3
%val6 = sub <4 x i1> %val5, %val0
ret <4 x i1> %val6
}
=>
define <4 x i1> @fun0(<4 x i1> %val0, <4 x i1> %val1, <4 x i1> %val2) nofree willreturn memory(none) {
entry:
%val4 = xor <4 x i1> %val0, { 0, undef, undef, 1 }
%#0 = and <4 x i1> %val4, %val1
%val6 = xor <4 x i1> %#0, { 0, undef, undef, 1 }
ret <4 x i1> %val6
}
Transformation doesn't verify!
ERROR: Target's return value is more undefined
Example:
<4 x i1> %val0 = < #x0 (0), #x0 (0), #x0 (0), #x0 (0) >
<4 x i1> %val1 = < #x0 (0), #x0 (0), #x1 (1), #x0 (0) >
<4 x i1> %val2 = < #x0 (0), #x0 (0), #x0 (0), #x0 (0) >
```
`tgt` produces `<0, undef, undef, 1>` while `src` produces `<0, 0, undef, 1>` for the given example input.
This breaks refinement relation.
https://github.com/llvm/llvm-project/blob/f329e3ed9070aee3f4c0ebc80ed62f5c4b645d73/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L4196-L4201
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU2P4zYM_TXMhZhApvx58GG-AhRYdIHBAm2Psk0n2rWlQJIzk_76wk464ywcdHLoBoFiKeTjIx8tKu_11jCXkDxA8rRSQ9hZV1bWfB8MryrbHMtdCHsP8h5oA7RRnT4wrbvu0K-t2wJtagba_A20-f3Vy78ciCcQ9-c1FefvtL375Odk3XCrDSPIxxjfUEcgnxFi0Q5GAOWXx5QcVCeAHnHhPLpyTkAFQvZwCscmuOOY5rTDs41EkE-omuY6cPaA08NsQcieLnHiCefNup9wsgecaA-m4fbi4QQyBjgnd4GXnHiZRV7xh5u8dEsnNz9US27JQjTHYck0Pev7b5ogn0A-_0rdjG0dM77qrnMcBmew5966I1BurOFPSHtNkhmn_1LnAw9Iik9KEp3d5oossRghb2HxSam-OWV8a12vgrYGG8veAGUBD-x0ewSK5m_w88vL1xeQ9_hNuS0HoMzjud4H1Q2M2mNvHZ84acPNhfeb6vcdv5d-qdBT_iDH6sg3gUC5ACpO5brpAN87cKmXbgwTjQfRzWHo_8jm8hL96X4N2wCpwL2zzVCzx9FOPl7rlxE0Ffi60x2Ppt7V17zFomdrHYYd41Yf2CCf9EVt9kNYn_trpz1WjtWPsVPGlujZBHTcTQ23nvO_HC1bHXZDta5tD7QZB8z5527v7HeuA9Cm6mwFtGklFSy5KUQmFLNs41pwVeeCm5TapI6rNE6aTM5w9Oj33vseaPOb8eHR9pUeb4v57t40X92f1q3r_R5IfomjIr37EpOIFhSYraumlE0hC7XiMspIREIUcb7alTKvOY8SUdWUtHmr0rzOWaq0UZUqojxe6ZIExSITcSTjQuTrtEi55SapWYg0zzOIBfdKd-9zd6W9H7gsskyKVacq7vw0w4kMv-L0JxCNI92VUw2rYeshFp32wX-gBB06Lv9w1myxV_4HN9iz2zLaFg9cB-vQ7tkp03isjjgr0mpwXXmzfhOxsfgn4oeS_gkAAP__Y4tFsA">