[PATCH] D113939: [runtime-unroll] Remove restriction about unrolling multiple exit loops

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 15 13:54:22 PST 2021


reames created this revision.
reames added reviewers: apilipenko, annatom, nikic, Whitney, hoy.
Herald added subscribers: zzheng, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

This change simply removes entirely a restriction in the runtime unrolling implementation which prevents us from unrolling loops with multiple exits in anything except the narrowest circumstances.

For context here, I think its important to note that this code originally didn't handle unrolling multiple exit loops (at all, it would crash), and then we selectively added one case with known motivation, and then iteratively widened the cases which could be done under force flags.  At this point, there's no known correctness limitations left.  I highlight this history mostly because it's tempting to think the existing heuristic is well justified, and frankly, it wasn't.  It was simply us being conservative along the way.

For additional context, the unroll pass will do it's own cost model before invoking this code at all.  That cost model is fairly coarse; it's entirely code size based.  With the code here, we effectively had a two level cost model.

With all the context, why do I believe we should enable this?  Because we're already runtime unrolling cases which are directly analogous to the multiple exit edge case.  At the simplest, consider a C loop where all break statements are replaced with continues.  (Ignore the fact this might not compute the same result.)  We'd unroll the continue form, but not the break form.

Now, with all of that nice justification out of the way, I have to admit that I haven't benchmarked this at all yet.  I'll be able to share some numbers in the near future, but help from others in benchmarking their workload of choice is very welcome.  :)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113939

Files:
  llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
  llvm/test/Transforms/LoopUnroll/ARM/multi-blocks.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop-at-most-two-exits.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop.ll
  llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113939.387390.patch
Type: text/x-patch
Size: 71818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211115/cc6df5bc/attachment-0001.bin>


More information about the llvm-commits mailing list