[PATCH] D103362: [LoopUnroll] Separate peeling from unrolling

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 29 10:00:43 PDT 2021


nikic created this revision.
nikic added reviewers: reames, fhahn, efriedma.
Herald added subscribers: zzheng, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Loop peeling is currently performed as part of UnrollLoop(). The whole setup is somewhat odd, here is my current understanding of the situation:

- Outside test scenarios, peeling will always be performed as part of an unroll with `Count=1`: https://github.com/llvm/llvm-project/blob/ffb48d48e45c72ed81dda4983ccb06e800cdbbd0/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L873-L879
- Of course, unrolling with count one does not do a great deal. My deduced reason for doing this is to run `simplifyLoopAfterUnroll()`, without which many tests indeed fail.
- When testing, it's possible to specify both `-unroll-peel-count` and `-unroll-count`, in which case both peeling and unrolling will be performed. However, if you actually try to do this, you apparently run into this miscompile: https://bugs.llvm.org/show_bug.cgi?id=45939 / D80080 <https://reviews.llvm.org/D80080>

Based on that reasoning (and suggested by @efriedma on the referenced review) I've moved the peeling code out of UnrollLoop() into tryToUnrollLoop() and perform only peeling if it is requested, and no unrolling.

TBH the way peeling is implemented has left me very confused, so I'm not sure I'm doing the right thing here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103362

Files:
  llvm/include/llvm/Transforms/Utils/UnrollLoop.h
  llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
  llvm/lib/Transforms/Utils/LoopUnroll.cpp
  llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
  llvm/test/Transforms/LoopUnroll/pr33437.ll
  llvm/test/Transforms/LoopUnroll/pr45939-peel-count-and-complete-unroll.ll
  llvm/test/Transforms/LoopUnroll/wrong_assert_in_peeling.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103362.348641.patch
Type: text/x-patch
Size: 18835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210529/54c1a03e/attachment.bin>


More information about the llvm-commits mailing list