summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2018-11-08 03:57:55 +0000
committerwhitequark <whitequark@whitequark.org>2018-11-08 03:57:55 +0000
commit3580ac6125dd6bc59b5e60134cf586687af01ec7 (patch)
tree8af78f4754cc48ed938eb5407d70dfae8c41079c
parent897171902b2cd6b90e2f555f6a29b5f6a92e83cf (diff)
downloadbcm5719-llvm-3580ac6125dd6bc59b5e60134cf586687af01ec7.tar.gz
bcm5719-llvm-3580ac6125dd6bc59b5e60134cf586687af01ec7.zip
[MergeFuncs] Call removeUsers() prior to unnamed_addr RAUW
Summary: For unnamed_addr functions we RAUW instead of only replacing direct callers. However, functions in which replacements were performed currently are not added back to the worklist, resulting in missed merging opportunities. Fix this by calling removeUsers() prior to RAUW. Reviewers: jfb, whitequark Reviewed By: whitequark Subscribers: rkruppe, llvm-commits Differential Revision: https://reviews.llvm.org/D53262 llvm-svn: 346385
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp1
-rw-r--r--llvm/test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll35
2 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index e8056e6cc61..49b3eacbaff 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -770,6 +770,7 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
GlobalNumbers.erase(G);
// If G's address is not significant, replace it entirely.
Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType());
+ removeUsers(G);
G->replaceAllUsesWith(BitcastF);
} else {
// Redirect direct callers of G to F. (See note on MergeFunctionsPDI
diff --git a/llvm/test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll b/llvm/test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll
new file mode 100644
index 00000000000..5902edc0e88
--- /dev/null
+++ b/llvm/test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll
@@ -0,0 +1,35 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; After test3 and test4 have been merged, we should detect that
+; test1 and test2 can also be merged.
+
+; CHECK: define void @test4() unnamed_addr
+; CHECK-NEXT: tail call void @test3()
+; CHECK: define void @test2() unnamed_addr
+; CHECK-NEXT: tail call void @test1()
+
+declare void @dummy()
+
+define void @test1() unnamed_addr {
+ call void @test3()
+ call void @test3()
+ ret void
+}
+
+define void @test2() unnamed_addr {
+ call void @test4()
+ call void @test4()
+ ret void
+}
+
+define void @test3() unnamed_addr {
+ call void @dummy()
+ call void @dummy()
+ ret void
+}
+
+define void @test4() unnamed_addr {
+ call void @dummy()
+ call void @dummy()
+ ret void
+}
OpenPOWER on IntegriCloud