From 5554edabef3814395360c37e9854fa4aa7b1731e Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 19 Aug 2016 16:37:40 +0000 Subject: [PATCH] [CloneFunction] Don't remove unrelated nodes from the CGSSC CGSCC use a WeakVH to track call sites. RAUW a call within a function can result in that WeakVH getting confused about whether or not the call site is still around. llvm-svn: 279268 --- llvm/lib/Transforms/Utils/CloneFunction.cpp | 6 +++++ .../Transforms/Inline/inline_constprop.ll | 26 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index 4f1052d81433..4d33e22fecfb 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -566,6 +566,12 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, if (!I) continue; + // Skip over non-intrinsic callsites, we don't want to remove any nodes from + // the CGSCC. + CallSite CS = CallSite(I); + if (CS && CS.getCalledFunction() && !CS.getCalledFunction()->isIntrinsic()) + continue; + // See if this instruction simplifies. Value *SimpleV = SimplifyInstruction(I, DL); if (!SimpleV) diff --git a/llvm/test/Transforms/Inline/inline_constprop.ll b/llvm/test/Transforms/Inline/inline_constprop.ll index ab9e90ca27c6..c13e023017a0 100644 --- a/llvm/test/Transforms/Inline/inline_constprop.ll +++ b/llvm/test/Transforms/Inline/inline_constprop.ll @@ -299,8 +299,8 @@ entry: } ; CHECK-LABEL: define i32 @PR28802( -; CHECK: call i32 @PR28802.external(i32 0) -; CHECK: ret i32 0 +; CHECK: %[[call:.*]] = call i32 @PR28802.external(i32 0) +; CHECK: ret i32 %[[call]] define internal i32 @PR28848.callee(i32 %p2, i1 %c) { entry: @@ -322,3 +322,25 @@ entry: } ; CHECK-LABEL: define i32 @PR28848( ; CHECK: ret i32 0 + +define internal void @callee7(i16 %param1, i16 %param2) { +entry: + br label %bb + +bb: + %phi = phi i16 [ %param2, %entry ] + %add = add i16 %phi, %param1 + ret void +} + +declare i16 @caller7.external(i16 returned) + +define void @caller7() { +bb1: + %call = call i16 @caller7.external(i16 1) + call void @callee7(i16 0, i16 %call) + ret void +} +; CHECK-LABEL: define void @caller7( +; CHECK: %call = call i16 @caller7.external(i16 1) +; CHECK-NEXT: ret void