[all-commits] [llvm/llvm-project] b43a4d: [LoopPeeling] Support peeling loops with non-latch...

Nikita Popov via All-commits all-commits at lists.llvm.org
Fri Oct 7 03:36:26 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b43a4d0850d5690e4399acda7ec6b5aca40b9eff
      https://github.com/llvm/llvm-project/commit/b43a4d0850d5690e4399acda7ec6b5aca40b9eff
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2022-10-07 (Fri, 07 Oct 2022)

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

  Log Message:
  -----------
  [LoopPeeling] Support peeling loops with non-latch exits

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.

Differential Revision: https://reviews.llvm.org/D134803




More information about the All-commits mailing list