OSDN Git Service

[LoopPeeling] Get rid of Phis that become invariant after N steps
authorMax Kazantsev <max.kazantsev@azul.com>
Mon, 17 Apr 2017 09:52:02 +0000 (09:52 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Mon, 17 Apr 2017 09:52:02 +0000 (09:52 +0000)
commit63c0d1d702ca0f990b6f2915e7724c143b71e9ce
treee63b899cdba5dc0230d7384ad393e2a57d636987
parent38eae0ca5ea75c986b4b8b481f5f6911080f983f
[LoopPeeling] Get rid of Phis that become invariant after N steps

This patch is a generalization of the improvement introduced in 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) is infinite.
Notice that if we peel a loop, all Phis with Depth = 1 become invariants,
and all other Phis with finite depth decrease the depth by 1.
Thus, peeling N first iterations allows us to turn all Phis with Depth <= N
into invariants.

Reviewers: reames, apilipenko, mkuper, skatkov, anna, sanjoy

Reviewed By: sanjoy

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300446 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/LoopUnrollPeel.cpp
test/Transforms/LoopUnroll/peel-loop-not-forced.ll