amehsan wrote:
> Wouldn't this be incorrect in the case where `cond()` is `true`, i.e. the loop is infinite? I think you need to prove that the loop is finite.
added a check that the loop is finite and a testcase for infinite loop. Repeatd experiments that was reported in the PR description (a little reduction in the number of trivial unswitches, no impact on O2 compile time consistent with the previous experiment):
O2 experiments:
```
Program simple-loop-unswitch.NumTrivial
bef2 aft2 diff
Bullet/bullet 12.00 inf%
lencod/lencod 67.00 inf%
mafft/pairlocalalign 77.00 inf%
tramp3d-v4/tramp3d-v4 184.00 inf%
consumer-typeset/consumer-typeset 2.00 6.00 200.0%
sqlite3/sqlite3 3.00 6.00 100.0%
ClamAV/clamscan 5.00 9.00 80.0%
7zip/7zip-benchmark 4.00 7.00 75.0%
SPASS/SPASS 4.00 4.00 0.0%
kimwitu++/kc
Geomean difference 80.0%
Program compile_time
O2B O2U diff
tramp3d-v4/tramp3d-v4 35.32 35.64 0.9%
mafft/pairlocalalign 15.23 15.27 0.2%
SPASS/SPASS 21.83 21.85 0.1%
7zip/7zip-benchmark 113.24 113.25 0.0%
kimwitu++/kc 24.04 24.04 -0.0%
sqlite3/sqlite3 17.72 17.69 -0.2%
lencod/lencod 25.91 25.85 -0.2%
ClamAV/clamscan 24.81 24.74 -0.3%
Bullet/bullet 51.14 50.99 -0.3%
consumer-typeset/consumer-typeset 15.90 15.84 -0.4%
Geomean difference -0.0%
```
O3 experiments
```
Program simple-loop-unswitch.NumTrivial
bef3 aft3 diff
Bullet/bullet 12.00 inf%
mafft/pairlocalalign 82.00 inf%
tramp3d-v4/tramp3d-v4 181.00 inf%
lencod/lencod 18.00 88.00 388.9%
consumer-typeset/consumer-typeset 2.00 6.00 200.0%
ClamAV/clamscan 5.00 11.00 120.0%
sqlite3/sqlite3 3.00 6.00 100.0%
SPASS/SPASS 5.00 6.00 20.0%
7zip/7zip-benchmark 7.00 7.00 0.0%
kimwitu++/kc
Geomean difference 106.5%
Program simple-loop-unswitch.NumBranches
bef3 aft3 diff
mafft/pairlocalalign 218.00 231.00 6.0%
ClamAV/clamscan 74.00 77.00 4.1%
7zip/7zip-benchmark 81.00 81.00 0.0%
Bullet/bullet 68.00 68.00 0.0%
SPASS/SPASS 94.00 94.00 0.0%
consumer-typeset/consumer-typeset 30.00 30.00 0.0%
kimwitu++/kc 4.00 4.00 0.0%
sqlite3/sqlite3 47.00 47.00 0.0%
tramp3d-v4/tramp3d-v4 203.00 203.00 0.0%
lencod/lencod 312.00 306.00 -1.9%
Geomean difference 0.8%
```
https://github.com/llvm/llvm-project/pull/193989