diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp --- a/llvm/lib/Analysis/LazyCallGraph.cpp +++ b/llvm/lib/Analysis/LazyCallGraph.cpp @@ -1484,6 +1484,12 @@ // 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 --- /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 +} +