[PATCH] D34806: [MergeFunctions] Merge small functions if possible without a thunk
whitequark via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 21:43:36 PDT 2017
whitequark updated this revision to Diff 104596.
whitequark added a comment.
Cosmetic change in debug output.
Repository:
rL LLVM
https://reviews.llvm.org/D34806
Files:
lib/Transforms/IPO/MergeFunctions.cpp
test/Transforms/MergeFunc/merge-small-unnamed-addr.ll
test/Transforms/MergeFunc/no-merge-small.ll
Index: test/Transforms/MergeFunc/no-merge-small.ll
===================================================================
--- /dev/null
+++ test/Transforms/MergeFunc/no-merge-small.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; CHECK: @a
+define void @a() {
+ ret void
+}
+
+; CHECK: @b
+define void @b() {
+ ret void
+}
Index: test/Transforms/MergeFunc/merge-small-unnamed-addr.ll
===================================================================
--- /dev/null
+++ test/Transforms/MergeFunc/merge-small-unnamed-addr.ll
@@ -0,0 +1,14 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; CHECK-NOT: @b
+
+ at x = constant { void ()*, void ()* } { void ()* @a, void ()* @b }
+; CHECK: { void ()* @a, void ()* @a }
+
+define internal void @a() unnamed_addr {
+ ret void
+}
+
+define internal void @b() unnamed_addr {
+ ret void
+}
Index: lib/Transforms/IPO/MergeFunctions.cpp
===================================================================
--- lib/Transforms/IPO/MergeFunctions.cpp
+++ lib/Transforms/IPO/MergeFunctions.cpp
@@ -647,6 +647,16 @@
return;
}
+ // Don't merge tiny functions using a thunk, since it can just end up
+ // making the function larger.
+ if (F->size() == 1) {
+ if (F->front().size() <= 2) {
+ DEBUG(dbgs() << "writeThunk: " << F->getName()
+ << " is too small to bother creating a thunk for\n");
+ return;
+ }
+ }
+
BasicBlock *GEntryBlock = nullptr;
std::vector<Instruction *> PDIUnrelatedWL;
BasicBlock *BB = nullptr;
@@ -779,18 +789,6 @@
const FunctionNode &OldF = *Result.first;
- // Don't merge tiny functions, since it can just end up making the function
- // larger.
- // FIXME: Should still merge them if they are unnamed_addr and produce an
- // alias.
- if (NewFunction->size() == 1) {
- if (NewFunction->front().size() <= 2) {
- DEBUG(dbgs() << NewFunction->getName()
- << " is to small to bother merging\n");
- return false;
- }
- }
-
// Impose a total order (by name) on the replacement of functions. This is
// important when operating on more than one module independently to prevent
// cycles of thunks calling each other when the modules are linked together.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34806.104596.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170629/350427cb/attachment.bin>
More information about the llvm-commits
mailing list