[LPM] Fix PR18642, a pretty nasty bug in IndVars that "never mattered"
authorChandler Carruth <chandlerc@gmail.com>
Wed, 29 Jan 2014 04:40:19 +0000 (04:40 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 29 Jan 2014 04:40:19 +0000 (04:40 +0000)
commit6a67a3f3ec5c70c3a9473068fe20c97c612d9780
treebe1362f305461451a5d2dd9243fde74df2115e5b
parent8dc253e97b1a119acb9a8f3c2f8305871a3906e1
[LPM] Fix PR18642, a pretty nasty bug in IndVars that "never mattered"
because of the inside-out run of LoopSimplify in the LoopPassManager and
the fact that LoopSimplify couldn't be "preserved" across two
independent LoopPassManagers.

Anyways, in that case, IndVars wasn't correctly preserving an LCSSA PHI
node because it thought it was rewriting (via SCEV) the incoming value
to a loop invariant value. While it may well be invariant for the
current loop, it may be rewritten in terms of an enclosing loop's
values. This in and of itself is fine, as the LCSSA PHI node in the
enclosing loop for the inner loop value we're rewriting will have its
own LCSSA PHI node if used outside of the enclosing loop. With me so
far?

Well, the current loop and the enclosing loop may share an exiting
block and exit block, and when they do they also share LCSSA PHI nodes.
In this case, its not valid to RAUW through the LCSSA PHI node.

Expected crazy test included.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200372 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/IndVarSimplify.cpp
test/Transforms/IndVarSimplify/lcssa-preservation.ll [new file with mode: 0644]