From 0afd10b4030dcca36c85f24942be8ea860df8d9e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 19 Aug 2021 20:56:09 +0200 Subject: [PATCH] [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 --- llvm/lib/Transforms/Scalar/LoopPassManager.cpp | 4 ++++ llvm/test/Other/loop-mssa-not-preserved.ll | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 llvm/test/Other/loop-mssa-not-preserved.ll diff --git a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp index f4fce4871331..9f61aa0ed918 100644 --- a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp @@ -285,6 +285,10 @@ PreservedAnalyses FunctionToLoopPassAdaptor::run(Function &F, else PI.runAfterPass(*Pass, *L, PassPA); + if (LAR.MSSA && !PassPA.getChecker().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 diff --git a/llvm/test/Other/loop-mssa-not-preserved.ll b/llvm/test/Other/loop-mssa-not-preserved.ll new file mode 100644 index 000000000000..38390262f113 --- /dev/null +++ b/llvm/test/Other/loop-mssa-not-preserved.ll @@ -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 +}