[llvm] [LoopInfo] Derive Loop::contains(BlockT*) from the block-to-loop map (PR #207613)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 23:07:41 PDT 2026
aengelke wrote:
> Which part is O(N^3)?
Sorry, just checked again. It's not LoopInfo itself that's O(n^3), but some loop passes (licm, loop-load-elim, loop-simplifycfg) are. (I do recall seeing LoopAnalysis growing stronger at some point, but I can't reproduce it right now; maybe that changes in the mean time.)
[Benchmark src](https://github.com/tpde2/tpde/tree/master/tpde-llvm/test/benchmark); x^2 coeff > 1 indicates super-quadratic growth (I should fix the regression at some point). To find parts with large growth, profile opt -O2 with a large input.
```
$ ./tpde2/tpde-llvm/test/benchmark/run.py --timeout=10 tpde2/tpde-llvm/test/benchmark/loop-nest-reducible.test ~/llvm-build3/bin/opt -passes="require<loops>" -disable-output
1 0.0 31700.0
2 0.0 32360.0
4 0.0 31768.0
8 0.0 31752.0
16 0.0 31704.0
32 0.0 31664.0
64 0.0 31668.0
128 0.0 32528.0
256 0.0 34752.0
512 0.01 38620.0
1024 0.05 59348.0
2048 0.19 141524.0
4096 0.85 462548.0
6144 2.06 981596.0
8192 3.67 1739412.0
10240 5.69 2564352.0
12288 8.37 3803352.0
Polynomial: 0.00018184 - 0.03072172·x + 1.02693449·x²
$ ./tpde2/tpde-llvm/test/benchmark/run.py --timeout=40 tpde2/tpde-llvm/test/benchmark/loop-nest-reducible.test ~/llvm-build3/bin/opt -passes="licm" -disable-output
1 0.0 31668.0
2 0.0 32416.0
4 0.0 33168.0
8 0.0 33108.0
16 0.0 33284.0
32 0.0 33224.0
64 0.0 32464.0
128 0.01 33196.0
256 0.04 35596.0
512 0.25 43988.0
1024 2.19 77780.0
1536 7.55 133776.0
2048 18.07 211348.0
2560 35.16 316500.0
Polynomial: 0.01069479 - 0.48592205·x + 1.4478261·x²
$ ./tpde2/tpde-llvm/test/benchmark/run.py --timeout=40 tpde2/tpde-llvm/test/benchmark/loop-nest-reducible.test ~/llvm-build3/bin/opt -passes="loop-load-elim" -disable-output
1 0.0 31696.0
2 0.0 32396.0
4 0.0 31700.0
8 0.0 31700.0
16 0.0 32424.0
32 0.0 31700.0
64 0.0 31636.0
128 0.02 32404.0
256 0.16 34728.0
512 1.23 43272.0
768 4.87 57072.0
1024 11.64 76984.0
1280 24.23 103060.0
Polynomial: 0.01421301 - 0.55343823·x + 1.50243083·x²
$ ./tpde2/tpde-llvm/test/benchmark/run.py --timeout=40 tpde2/tpde-llvm/test/benchmark/loop-nest-reducible.test ~/llvm-build3/bin/opt -passes="loop-simplifycfg" -disable-output
1 0.0 32512.0
2 0.0 32560.0
4 0.0 32456.0
8 0.0 32468.0
16 0.0 32468.0
32 0.0 31700.0
64 0.0 32468.0
128 0.01 32468.0
256 0.04 34600.0
512 0.27 43156.0
1024 2.34 79236.0
1536 8.09 133896.0
2048 18.82 212180.0
Polynomial: 0.01051385 - 0.47004665·x + 1.43837519·x²
```
https://github.com/llvm/llvm-project/pull/207613
More information about the llvm-commits
mailing list