<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58122>58122</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SimpleLoopUnswitch] Missed Opportunity to unswitch
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
barakgla
</td>
</tr>
</table>
<pre>
The code : [Missed Opportunity to unswitch](https://godbolt.org/z/4xv5Edb85)
If I compiled the code with trunk clang (clang -O3 -emit-llvm) I get the below if-condition is not unswitched although it is looked profitable to unswitch in this case :
`if(size >= size_z)
val = 256;`
If I compiled the code with older version of Clang(14.0.0) and with the legacy PM I got that the code is unswitched.
I know the legacy PM did used the LoopUnswitch as default where in new PM there is only the SimpleLoopUnswitch.
In this case , I think problem is the SimpleLoopUnswitch doesn't even try to unswitch SelectInst like the instruction :
`%15 = select i1 %7, i32 %14, i32 64`
where this is not the terminator of the basic block.
The original LoopUnswitch on the other hand did try to unswitch the SelectInst instructions within the basic block even if those instructions aren't terminators.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVNuOmzAQ_Rp4GQWBuSQ88LC3Sit1tZXaPlcGBnDj2JFtkma_vmMnu1m2VVUUiAczM-ecGU-r-1PzbULodI8Q5TcAUXn7JKzFHp73e23crIQ7gdMwK3sUrpui8j5im8m5vSWHiH2i36j7VkuXaDOS9UJ38etQPvTtpoxYHaX3UXpzfj4O8EjZdnshKYV7TU2RJ3BmVlvoJFcjUIrzYvWcwwp3wq2kPOwoGvmP6IJri1IfQQyrTqteOKEVCAtKuzewlINLN-l5nEA4vyu13tLbvdGDcLyV-J4bCEWB6auO27MeF-xVKgaCZMWLf_0Q5ffg1z9e3uhBuA5cgt9kZRXlt-T2v9y17NHAAY31LPQAd549pcyKJE1Sz5ur_qITeUoceXeCL09eDu3l4O4akhhcFUgWGGCrSLNliF70MNsLps9a77-_6sEt9DjwWTo4TmjQC6Tw6J3c2baglTwFz69it5f43n-ZeqEtuyPkZFPFqRZUh52P9fcw0Gu0KmJrB3hACmMWHQlfUWLnHpV1IMUWQxRBlpm70BSLQkaszMpQJBvcQGSEplx7RCJnfp0Vr0ZVvNXwzD8wuDSZT-PQ7ITiThtftNCU3IoOWqm77YW-P2DaiJG-k0t5tQou2msJky-wL8VHekGUK8V3zGxoCKE-Jj7LJDwgbXHpwQ2epbxCt0mMTVZVxSZlVVnEfZP3dV7z2AknsaGR8GdNaAzAvwdFPBvZfJgThHZuEzoDZJzPc_hbUQv8JH5kUsgZLS3KTcZYPDU5Y9V6U3Wsr9v1UFcDy7DM-yIr8rbGisWS0xywHiVhikXDUsayNM2zPEvLIsmrtE7zdV1VdZrhwKIixR0XMvGJ_cSKTRMwtPNoaVMK6-x1k1srRoX4Gp_PpKlpWm74dpQ8DnibAPY3G0W_Yg">