<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82350>82350</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] fold select of select with common argument
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sftlbcn
</td>
</tr>
</table>
<pre>
fold other select to logical and/or if either cmp is free to invert
https://alive2.llvm.org/ce/z/aSYXfg
```
----------------------------------------
define i32 @src_or(i32 %x, i32 %y, i32 %z, i1 %cmp1) {
#0:
%cmp2 = icmp eq i32 %z, 0
%sel1 = select i1 %cmp1, i32 %x, i32 %y
%sel2 = select i1 %cmp2, i32 %sel1, i32 %x
ret i32 %sel2
}
=>
define i32 @tgt_or(i32 %x, i32 %y, i32 %z, i1 %cmp1) {
#0:
%cmp2_inv = icmp ne i32 %z, 0
%sel1 = select i1 %cmp2_inv, i1 1, i1 %cmp1
%sel2 = select i1 %sel1, i32 %x, i32 %y
ret i32 %sel2
}
Transformation seems to be correct!
----------------------------------------
define i32 @src_and(i32 %x, i32 %y, i32 %z, i1 %cmp1) {
#0:
%cmp2 = icmp eq i32 %z, 0
%sel1 = select i1 %cmp2, i32 %x, i32 %y
%sel2 = select i1 %cmp1, i32 %sel1, i32 %x
ret i32 %sel2
}
=>
define i32 @tgt_and(i32 %x, i32 %y, i32 %z, i1 %cmp1) {
#0:
%cmp2_inv = icmp ne i32 %z, 0
%sel1 = select i1 %cmp1, i1 %cmp2_inv, i1 0
%sel2 = select i1 %sel1, i32 %y, i32 %x
ret i32 %sel2
}
Transformation seems to be correct!
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVcFu2zgQ_ZrRhYhBjUTLPuiQxCtgz7uH9hRQ4khmQZEuSTtNvr4QoyRyG7Q1ggA1DHsIvpk38_CkkSHowRLVIG5A7DJ5jHvn69BH03Y2a516qHtnFHNxT54FMtRFFh0zbtCdNExaBdg4z3TPSCdQNx6YDqz3RBNS2xP5CHwH_Hof4yFAcQ3YADbS6BPhypjTuHJ-AGw6Amwep6v_Pn_qh6ckWPP5m45Xf_h5QivqtSWmC2RQ8uC7O-cBN-mM4hvgLZvjh0X8mOJ8CrvxkANuGVQ3cztY8GmEdGAzBBkUO6an0enrWRW-AAYyeQLOOi4ZXrjPezpLxjeTcZEwMZzVmvM9xQUE50mq3RwUOyj-eUuwOMQPEuxO29OraM-Ml4iWSsy8-Q_8v5PtJ53e0PzXmv3vpQ2986OM2lkWiMYw2b0l1jnvqYuAcx_L3_e6Nz1vf5t98T32zT_Yvh-k2Pv9e-7ZpZv5pf59uFy0S_z7_ALOVF2obbGVGdV5xTdlkZdine1ryVHQRlWiardbUa1VLtpWULXpy7zKaZ3pGjmWHJHnmFfFetWqvu8rpYSSquRSQMlplNq8bINMh3CkeoOF4JmRLZmQlhSipXuWLgFx2lm-nnKu2uMQoORGhxheq0QdTdpu_9oQb93YaksgdiwttVlS1z9H9zruWefG0Vkm_XAcycbs6E19vrgGHffHdtW5EbCZqOa_q4N3X5JyTWowADZpgO8BAAD__1XL_Zs">