[llvm] 6cbb35d - [NewPM] Bail out of devirtualization wrapper if the current SCC is invalidated

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 19 15:08:05 PDT 2021


Author: Arthur Eubanks
Date: 2021-07-19T15:07:30-07:00
New Revision: 6cbb35dd3b2f115105d2d9b6da52f2bfc337891c

URL: https://github.com/llvm/llvm-project/commit/6cbb35dd3b2f115105d2d9b6da52f2bfc337891c
DIFF: https://github.com/llvm/llvm-project/commit/6cbb35dd3b2f115105d2d9b6da52f2bfc337891c.diff

LOG: [NewPM] Bail out of devirtualization wrapper if the current SCC is invalidated

The specific case that triggered this was when inlining a recursive
internal function into itself caused the recursion to go away, allowing
the inliner to mark the function as dead. The inliner marks the SCC as
invalidated but does not provide a new SCC to continue with.

This matches the implementations of ModuleToPostOrderCGSCCPassAdaptor
and CGSCCPassManager.

Fixes PR50363.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D106306

Added: 
    llvm/test/Other/devirt-invalidated.ll

Modified: 
    llvm/lib/Analysis/CGSCCPassManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 8043cc7fc742e..253cc0b0a5795 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -432,8 +432,13 @@ PreservedAnalyses DevirtSCCRepeatedPass::run(LazyCallGraph::SCC &InitialC,
       break;
     }
 
-    // Check that we didn't miss any update scenario.
-    assert(!UR.InvalidatedSCCs.count(C) && "Processing an invalid SCC!");
+    // If the CGSCC pass wasn't able to provide a valid updated SCC, the
+    // current SCC may simply need to be skipped if invalid.
+    if (UR.InvalidatedSCCs.count(C)) {
+      LLVM_DEBUG(dbgs() << "Skipping invalidated root or island SCC!\n");
+      break;
+    }
+
     assert(C->begin() != C->end() && "Cannot have an empty SCC!");
 
     // Check whether any of the handles were devirtualized.

diff  --git a/llvm/test/Other/devirt-invalidated.ll b/llvm/test/Other/devirt-invalidated.ll
new file mode 100644
index 0000000000000..c3ed5e53b3b04
--- /dev/null
+++ b/llvm/test/Other/devirt-invalidated.ll
@@ -0,0 +1,30 @@
+; RUN: opt -passes='devirt<0>(inline)' < %s -S | FileCheck %s
+
+; CHECK-NOT: internal
+; CHECK: define void @e()
+; CHECK-NOT: internal
+
+define void @e() {
+entry:
+  call void @b()
+  ret void
+}
+
+define internal void @b() {
+entry:
+  call void @d()
+  call void @c()
+  ret void
+}
+
+define internal void @d() {
+entry:
+  unreachable
+}
+
+define internal void @c() {
+entry:
+  call void @b()
+  call void @e()
+  ret void
+}


        


More information about the llvm-commits mailing list