[PM] Fix a bug in the new loop PM when handling functions with no loops.
authorChandler Carruth <chandlerc@gmail.com>
Fri, 10 Feb 2017 08:26:58 +0000 (08:26 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 10 Feb 2017 08:26:58 +0000 (08:26 +0000)
commit15870187915f10821f2994eea6071b7a2b4f4ca2
treecc4dbd80a52308b4729f734516ebe70be28897a8
parentf062b8936479b8b41c97416b10563dd9c1f0f493
[PM] Fix a bug in the new loop PM when handling functions with no loops.

Without any loops, we don't even bother to build the standard analyses
used by loop passes. Without these, we can't run loop analyses or
invalidate them properly. Unfortunately, we did these things in the
wrong order which would allow a loop analysis manager's proxy to be
built but then not have the standard analyses built. When we went to do
the invalidation in the proxy thing would fall apart. In the test case
provided, it would actually crash.

The fix is to carefully check for loops first, and to in fact build the
standard analyses before building the proxy. This allows it to
correctly trigger invalidation for those standard analyses.

An alternative might seem to be  to look at whether there are any loops
when doing invalidation, but this doesn't work when during the loop
pipeline run we delete the last loop. I've even included that as a test
case. It is both simpler and more robust to defer building the proxy
until there are definitely the standard set of analyses and indeed
loops.

This bug was uncovered by enabling GlobalsAA in the pipeline.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294728 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Scalar/LoopPassManager.h
test/Other/loop-pm-invalidation.ll [new file with mode: 0644]
test/Other/new-pass-manager.ll
test/Other/new-pm-defaults.ll