[PATCH] D31613: [LoopPeeling] Get rid of Phis that become invariant after N steps

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 11:56:08 PDT 2017


mkazantsev created this revision.

This patch is a generalization of the improvement introduced in https://reviews.llvm.org/rL296898.
Previously, we were able to peel one iteration of a loop to get rid of a Phi that becomes
an invariant on the 2nd iteration. In more general case, if a Phi becomes invariant after
N iterations, we can peel N times and turn it into invariant.
In order to do this, we for every Phi in loop's header we define the Invariant Depth value
which is calculated as follows:

Given %x = phi <Inputs from above the loop>, ..., [%y, %back.edge].

  If %y is a loop invariant, then Depth(%x) = 1.
  If %y is a Phi from the loop header, Depth(%x) = Depth(%y) + 1.
  Otherwise, Depth(%x) = 0.

Notice that if we peel a loop, all Phis with Depth = 1 become invariants,
and all other Phis with positive depth decrease the depth by 1.
Thus, peeling N first iterations allows us to turn all Phis with Depth <= N
into invariants.


https://reviews.llvm.org/D31613

Files:
  lib/Transforms/Utils/LoopUnrollPeel.cpp
  test/Transforms/LoopUnroll/peel-loop-not-forced.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31613.93904.patch
Type: text/x-patch
Size: 9532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170403/243d889a/attachment.bin>


More information about the llvm-commits mailing list