[IndVarSimplify] Rewrite loop exit values with their initial values from loop preheader
authorChen Li <meloli87@gmail.com>
Wed, 28 Oct 2015 04:45:47 +0000 (04:45 +0000)
committerChen Li <meloli87@gmail.com>
Wed, 28 Oct 2015 04:45:47 +0000 (04:45 +0000)
commit0c46270ed37a157cdb35548bceb0a6742ca29d8e
tree559848c9392361280cac8481fdcae11213f69121
parent50b691de429a0bbb4b272e87d58070bbae237f2a
[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@251492 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