<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113259>113259</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong narrowing `and` operands for undef inputs
</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/1d9b3222f3de7bad4ef27b7e4d7798f840097380/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L1981-L1987
Alive2 report: https://alive2.llvm.org/ce/z/jGx2Qz
---
```llvm
define i16 @zext_sub.2(i8 %x) {
#0:
%z = zext i8 %x to i16
%b = sub nsw i16 65531, %z
%r = and i16 %b, %z
%#1 = srem i16 %r, 255
ret i16 %#1
}
=>
define i16 @zext_sub.2(i8 %x) {
#0:
%#1 = sub i8 251, %x
%#2 = and i8 %#1, %x
%r = zext i8 %#2 to i16
ret i16 %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i8 %x = undef
Source:
i16 %z = #x0000 (0) [based on undef value]
i16 %b = #xfffb (65531, -5)
i16 %r = #x0000 (0) [based on undef value]
i16 %#1 = #x0000 (0)
Target:
i8 %#1 = #xff (255, -1)
i8 %#2 = #xff (255, -1)
i16 %r = #x00ff (255)
Source value: #x0000 (0)
Target value: #x00ff (255)
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/eJyslV2P6yYQhn_N5AYlwkP8deGL7MlJVanSUbdHbe8qMJCwsiECnM3ur69wvpxst1XVSitvCM-8vDOeMDwEs7VKNZA_Qb6e8SHunG-Es9uXwb7MhJNvzS7GfQC2AtwAbrYm7gaxaF0PuOm6w-XffO_di2oj4EZ0TgBuMlkLhoiaSVUKLpdKYylKtZRlWVe6WlJal6yiEx2T4r57boN2vg-Amx9tiF9cL4xV96uVld_8784v2v0ekP2U1VU2T88S6Bro6vRcdeagkHi1dz4CW5H7ZPi4vUjHL5zfAm7adMw74OblhyP-_D7Vms_n0yUU9PQ3mh-_kkobq4jJCgJL-q6O8Y8wiAUCVqYigPkRsCZQPp0VkNFkZVyQtP9OgK1JCiTnABJd0pswYmTCIIgNr-NZRZ6zDPDLqDAh_UhyK0-OMBd_AQGy7KToVX8BfQIxzy-cV_Gylfiz_XJ9_sDWwL7-TyW4-RlEKgLml9SO9xTesquuxj6S_rGkY-h9VSfp-Yfcrs3Io3GWSKeCBSwjOShv9BtgNu2Jr8_P355Tm_3Ku0GR3oSex3Z3hxx5v-_UNenLe04uByuVnsK_uMG3E_bk8dQlgOxIKaUEMP2GaqA15E-CByWJsyctckg-IF_fxYtrvNZapPhrB83zUWkC-_942PV9fpS45fmd-62KDzW5i9Q6xaWWTC6zm8vqrh3-Fv2Y0AStpxU_p8JWn7g--X2kPqqdNYe-5_5t0ueUtM571UYS7_orXICMGPsPCCWam07JeXTp7j2oz8HzLai8dz483F4z2TBZs5rPVJOVWOdFleXFbNeUNJdtJiosSsrauhVlhbQtZYFLKgSWM9MgxWVGESljeV4slF4qLFFTpgumtIQlVT033fV-nZkQBtVkGcO8nnVcqC6MowfRqlcy7gJimkS-GYeKGLYBlrQzIYabTDSxU81v3tktsdx792rslkBBuZVQUOL2ynMrA9HOn3vT2P0Qw2zw3b-fZ6OvNIzOxg8N_hkAAP__lJf5gA">