<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114734>114734</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] wrong folding of multiplication to shift for an undefined input
</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/390300d9f41df6ad71f0f4196ef4885d4bd5dc48/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp#L1769-L1783
Alive2 report: https://alive2.llvm.org/ce/z/qqQmaw
```llvm
----------------------------------------
define i32 @ashr_mul_times_3_div_2_exact_2.2(i32 %x) {
#0:
%#1 = sdiv i32 %x, 65535
%mul = mul nsw i32 %#1, 3
%ashr = ashr i32 %mul, 1
ret i32 %ashr
}
=>
define i32 @ashr_mul_times_3_div_2_exact_2.2(i32 %x) {
#0:
%#1 = sdiv i32 %x, 65535
%#2 = ashr i32 %#1, 1
%ashr = add nsw i32 %#1, %#2
ret i32 %ashr
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i32 %x = undef
Source:
i32 %#1 = #x00000000 (0) [based on undef value]
i32 %mul = #x00000000 (0)
i32 %ashr = #x00000000 (0)
Target:
i32 %#1 = #x00000000 (0)
i32 %#2 = #x00000000 (0)
i32 %ashr = #x00000080 (128)
Source value: #x00000000 (0)
Target value: #x00000080 (128)
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/eJzMlVGPmzgUhX-NebEmsq8hwAMPmaaRVqq02ulqXyOD7cQjY6e2yWT2169MICXttLuzT0VRgPjjcM7VjS8PQR-slA0qHlGxzfgQj843rbOH58E-Z60Tr80xxlNAbINgh2B30PE4tKvO9Qh2xpzn08PJu2fZRQS71rgWwY7VhBEiapVTodZclFQRldN6LVVeVYXIW1GILq8WOjo996fnNijn-4Bg95sN8YPrW23l_d3no1YxrLrTCQH7RMt1_fCJlhVDZIvI5vq9MfosAXt5cj4itsH3Ufi4vEovXzl_QLDr0kv-RrD78uWPnr8stdCaXD-j1_Gnh_94XGkhlbYSawYY5YSHo9_3g9lH3cuwZ3uhz3vYywvv4h5WgKAaSSguCGqMysfJBjCSAow3OK0jYBQjtsVB6DP--tAHvC4KVizIfjAjmM42vMxsEkg4W6DJ3siOFxPYDyZxdOK8jPNKoiZ_5Xa6YFvEPv4q0RGkxW_yzMHnQHe5hXirRpPUrPzzEtwamUftLBZOBougjPgsvVavCOiywT4-Pf3-lJr0L24GiXsdeh674x1y4f3JyFsR5sSj48EKqZb0Zzf47jv4VjME7EKmAyOoCIIakRoVjy0PUmBnr5L4nPygYnsnM_fS2yoL8FbRH5NTtbg_yPhOu_ck_G9L1UhSqG7stXpTeLb5ierV-Fvk96qT9tD33L8umpngznkvu4jjXdOEGaBY239BCFZcGykeokub8Vn-GJw2Rum98-Gb_S0TDRM1q3kmG1oysq6LqqqyY1O2tGJ5WVORV0AVF1CLNudraJWoSVFmugECOaUkJ3lBoVqVCrqyAAadWrOqalFOZM-1uW25mQ5hkA2lecnyzPBWmjDOIgArX_C4igDSaPLNOGXa4RBQTowOMXyViTqacYgtx0WxxS_e2QNWzghtD9iptPVFfTK6u_4lo8MhzRGsnMd8anhtpcDanoaYDd68f_yNrtPsmmKdG_gnAAD__0QSC2Q">