[llvm] 7a94d18 - [LazyCallGraph] Update libcall list when replacing a libcall node's function

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 27 11:08:53 PDT 2022


Author: Arthur Eubanks
Date: 2022-08-27T10:57:53-07:00
New Revision: 7a94d189ad1a49aace4e4008e10c8ab774198e67

URL: https://github.com/llvm/llvm-project/commit/7a94d189ad1a49aace4e4008e10c8ab774198e67
DIFF: https://github.com/llvm/llvm-project/commit/7a94d189ad1a49aace4e4008e10c8ab774198e67.diff

LOG: [LazyCallGraph] Update libcall list when replacing a libcall node's function

Otherwise when we visit all libcalls in
updateCGAndAnalysisManagerForPass(), the old libcall is dead and doesn't
have a node.

We treat libcalls conservatively in LazyCallGraph because any function
may introduce calls to them out of thin air.

It is weird to change the signature of a libcall since introducing calls
to the libcall with a different signature may break, but other passes
like deadargelim already do it, so let's preserve this behavior for now.

Fixes an issue found in D128830.

Reviewed By: psamolysov

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

Added: 
    llvm/test/Analysis/LazyCallGraph/replace-libcall.ll

Modified: 
    llvm/lib/Analysis/LazyCallGraph.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index 20a905e04a9d0..cb362d8305c72 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -1484,6 +1484,12 @@ void LazyCallGraph::RefSCC::replaceNodeFunction(Node &N, Function &NewF) {
   // Update various call graph maps.
   G->NodeMap.erase(&OldF);
   G->NodeMap[&NewF] = &N;
+
+  // Update lib functions.
+  if (G->isLibFunction(OldF)) {
+    G->LibFunctions.remove(&OldF);
+    G->LibFunctions.insert(&NewF);
+  }
 }
 
 void LazyCallGraph::insertEdge(Node &SourceN, Node &TargetN, Edge::Kind EK) {

diff  --git a/llvm/test/Analysis/LazyCallGraph/replace-libcall.ll b/llvm/test/Analysis/LazyCallGraph/replace-libcall.ll
new file mode 100644
index 0000000000000..372aade958acd
--- /dev/null
+++ b/llvm/test/Analysis/LazyCallGraph/replace-libcall.ll
@@ -0,0 +1,17 @@
+; RUN: opt -passes=inline,argpromotion < %s -S | FileCheck %s
+
+; Make sure we update the list of libcalls when we replace a libcall.
+
+; CHECK: define {{.*}}@a
+
+define void @a() {
+entry:
+  %call = call float @strtof(ptr noundef null, ptr noundef null)
+  ret void
+}
+
+define internal float @strtof(ptr noundef %0, ptr noundef %1) nounwind {
+entry:
+  ret float 0.0
+}
+


        


More information about the llvm-commits mailing list