[PATCH] D134803: [LoopPeeling] Support peeling loops with non-latch exits

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 05:23:09 PDT 2022


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

Loop peeling currently requires that a) the latch is exiting b) a branch and c) other exits are unreachable/deopt. This patch removes all of these limitations, and adds the necessary branch weight updating support. It essentially works the same way as before with latch -> exiting terminator and loop trip count -> per exit trip count.

It's worth noting that there are still other limitations in profitability heuristics: This patch enables peeling of loops to make conditions invariant (which is pretty much always highly profitable if possible), while peeling to make loads dereferenceable still checks that non-latch exits are unreachable and PGO-based peeling has even more conditions. Those checks could be relaxed later if we consider those cases profitable.

The motivation for this change is that loops using iterator adaptors in Rust often optimize very badly, and end up with a loop phi of the form phi(true, false) in the final result. Peeling eliminates that phi and conditions based on it, which enables a lot of follow-on simplification.


https://reviews.llvm.org/D134803

Files:
  llvm/lib/Transforms/Utils/LoopPeel.cpp
  llvm/test/Transforms/LoopUnroll/peel-branch-weights.ll
  llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll
  llvm/test/Transforms/LoopUnroll/peel-loop-irreducible.ll
  llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134803.463500.patch
Type: text/x-patch
Size: 26004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220928/84c80657/attachment.bin>


More information about the llvm-commits mailing list