<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121771>121771</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Commuted pattern is not handled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:instcombine,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/x1eqMrTWo
```
define i8 @rem_euclid_non_const_pow21(i8 %0, i8 %1) {
%pow2 = shl i8 1, %0
%rem = srem i8 %1, %pow2
%cond = icmp slt i8 %rem, 0
%add = add i8 %rem, %pow2
%sel = select i1 %cond, i8 %add, i8 %rem
ret i8 %sel
}
define i8 @rem_euclid_non_const_pow22(i8 %0, i8 %1) {
%pow2 = shl i8 1, %0
%rem = srem i8 %1, %pow2
%cond = icmp slt i8 %rem, 0
%add = add i8 %pow2, %rem
%sel = select i1 %cond, i8 %add, i8 %rem
ret i8 %sel
}
```
```
define i8 @rem_euclid_non_const_pow21(i8 %0, i8 %1) {
%notmask = shl nsw i8 -1, %0
%3 = xor i8 %notmask, -1
%sel = and i8 %1, %3
ret i8 %sel
}
define i8 @rem_euclid_non_const_pow22(i8 %0, i8 %1) {
%pow2 = shl nuw i8 1, %0
%rem = srem i8 %1, %pow2
%cond = icmp slt i8 %rem, 0
%add = select i1 %cond, i8 %pow2, i8 0
%sel = add i8 %rem, %add
ret i8 %sel
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzElE9v2zgQxT_N6ELYIEd_fdDBsSFgD3tbYI8GJU5tthTpilSc5NMXlKUkdYMiQBMUMEzJ_s0bz_PTSO_10RLVkN8Bogrdw9PjBRAh3ydyDCc31POHSevUY30K4ewh3QI2gM3RqdaZsHbDEbB5AmweBH3_d_jvfwd8CwWfX3yr6Iu2xHTFIOMD9QcaO6PVwTp76Jz14XB2FxSAVUQw54A7dr0UgBsG5R3wLYv3EWSQ7pk_mYiIiE4lfBvPgfrr1_HiWWK3lC4ynbNq4nTXn5k3YWYH6iPNF06qKxbPn4gbPU_m2pYMdYFpsTR5mUSqVzdRJZYOtHT2ZKJr5T6-v9cy_GPLPtizNy2bRK56y9wfb9mruH1C9ABz60Iv_bdnJ62_RHD1i53phDy4YdaZCyO2ErfTS6tuLE__TjDsePnscLxOx2_-9SUuunope7brjecwpuQdwUhUnapNupEJ1aJMC1HmVVokp5qrYpOlQpUkiXeqzfNNV1Zpm2ecVxmvEl0jx5wLXoicp3mxLkhJnsq2K5Bn-SaDjFMvtVkbc9_HfZho70eqBYqyFImRLRk_b9mIQLrV1ofO9a22FBcu7gCx196TWrlz0L1-kkE7Oy_joY5lq3Y8esi40T74l15BBzPt8H-sD7tZM9-znev7MZBiZxkCDZZpz6wL7CStMqSScTC3G12H09iuO9cDNtMPvR6r8-C-UhcAm2kwD9jMs93X-CMAAP__t73BWQ">