[IndVarSimplify] Rewrite loop exit values with their initial values from loop preheader
authorChen Li <meloli87@gmail.com>
Mon, 2 Nov 2015 22:00:15 +0000 (22:00 +0000)
committerChen Li <meloli87@gmail.com>
Mon, 2 Nov 2015 22:00:15 +0000 (22:00 +0000)
commitfb81c7b828fe82e7c0d400675dfdac6f77895fcd
treef0a05646d033d69efd64f91cef54fd41f912cd5a
parent5aa157fab605b41262b7e32fad59110432b319fb
[IndVarSimplify] Rewrite loop exit values with their initial values from loop preheader

Summary:
This patch adds support to check if a loop has loop invariant conditions which lead to loop exits. If so, we know that if the exit path is taken, it is at the first loop iteration. If there is an induction variable used in that exit path whose value has not been updated, it will keep its initial value passing from loop preheader. We can therefore rewrite the exit value with
its initial value. This will help remove phis created by LCSSA and enable other optimizations like loop unswitch.

Reviewers: sanjoy

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D13974

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251839 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/IndVarSimplify.cpp
test/Transforms/IndVarSimplify/rewrite-loop-exit-value.ll [new file with mode: 0644]
test/Transforms/LoopUnroll/scevunroll.ll