[LoopPassManager] Assert that MemorySSA is preserved if used

Currently it's possible to silently use a loop pass that does not
preserve MemorySSA in a loop-mssa pass manager, as we don't
statically know which loop passes preserve MemorySSA (as was the
case with the legacy pass manager).

However, we can at least add a check after the fact that if
MemorySSA is used, then it should also have been preserved.
Hopefully this will reduce confusion as seen in
https://bugs.llvm.org/show_bug.cgi?id=51020.

Differential Revision: https://reviews.llvm.org/D108399
This commit is contained in:
Nikita Popov 2021-08-19 20:56:09 +02:00
parent 8dc3fe0cd1
commit 0afd10b403
2 changed files with 21 additions and 0 deletions

View File

@ -285,6 +285,10 @@ PreservedAnalyses FunctionToLoopPassAdaptor::run(Function &F,
else
PI.runAfterPass<Loop>(*Pass, *L, PassPA);
if (LAR.MSSA && !PassPA.getChecker<MemorySSAAnalysis>().preserved())
report_fatal_error("Loop pass manager using MemorySSA contains a pass "
"that does not preserve MemorySSA");
#ifndef NDEBUG
// LoopAnalysisResults should always be valid.
// Note that we don't LAR.SE.verify() because that can change observed SE

View File

@ -0,0 +1,17 @@
; RUN: not --crash opt -passes='loop-mssa(loop-unroll-full)' 2>&1 < %s | FileCheck %s
; CHECK: LLVM ERROR: Loop pass manager using MemorySSA contains a pass that does not preserve MemorySSA
define void @test() {
entry:
br label %loop
loop:
%i = phi i32 [ 0, %entry ], [ %i.inc, %loop ]
%i.inc = add i32 %i, 1
%c = icmp ult i32 %i, 8
br i1 %c, label %loop, label %exit
exit:
ret void
}