[PATCH] D34805: [MergeFunctions] Replace all uses of unnamed_addr functions
whitequark via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 15 05:29:23 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315852: [MergeFunctions] Replace all uses of unnamed_addr functions. (authored by whitequark).
Changed prior to commit:
https://reviews.llvm.org/D34805?vs=104593&id=119076#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34805
Files:
llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr-bitcast.ll
llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr.ll
Index: llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr.ll
===================================================================
--- llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr.ll
+++ llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; CHECK-NOT: @b
+
+ at x = constant { i32 (i32)*, i32 (i32)* } { i32 (i32)* @a, i32 (i32)* @b }
+; CHECK: { i32 (i32)* @a, i32 (i32)* @a }
+
+define internal i32 @a(i32 %a) unnamed_addr {
+ %b = xor i32 %a, 0
+ %c = xor i32 %b, 0
+ ret i32 %c
+}
+
+define internal i32 @b(i32 %a) unnamed_addr {
+ %b = xor i32 %a, 0
+ %c = xor i32 %b, 0
+ ret i32 %c
+}
Index: llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr-bitcast.ll
===================================================================
--- llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr-bitcast.ll
+++ llvm/trunk/test/Transforms/MergeFunc/merge-unnamed-addr-bitcast.ll
@@ -0,0 +1,30 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+%A = type { i32 }
+%B = type { i32 }
+
+; CHECK-NOT: @b
+
+ at x = constant { i32 (i32)*, i32 (i32)* }
+ { i32 (i32)* bitcast (i32 (%A)* @a to i32 (i32)*),
+ i32 (i32)* bitcast (i32 (%B)* @b to i32 (i32)*) }
+; CHECK: { i32 (i32)* bitcast (i32 (%A)* @a to i32 (i32)*), i32 (i32)* bitcast (i32 (%A)* @a to i32 (i32)*) }
+
+define internal i32 @a(%A) unnamed_addr {
+ extractvalue %A %0, 0
+ xor i32 %2, 0
+ ret i32 %3
+}
+
+define internal i32 @b(%B) unnamed_addr {
+ extractvalue %B %0, 0
+ xor i32 %2, 0
+ ret i32 %3
+}
+
+define i32 @c(i32) {
+ insertvalue %B undef, i32 %0, 0
+ call i32 @b(%B %2)
+; CHECK: call i32 bitcast (i32 (%A)* @a to i32 (%B)*)(%B %2)
+ ret i32 %3
+}
Index: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
@@ -628,9 +628,15 @@
// call sites to point to F even when within the same translation unit.
void MergeFunctions::writeThunk(Function *F, Function *G) {
if (!G->isInterposable() && !MergeFunctionsPDI) {
- // Redirect direct callers of G to F. (See note on MergeFunctionsPDI
- // above).
- replaceDirectCallers(G, F);
+ if (G->hasGlobalUnnamedAddr()) {
+ // If G's address is not significant, replace it entirely.
+ Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType());
+ G->replaceAllUsesWith(BitcastF);
+ } else {
+ // Redirect direct callers of G to F. (See note on MergeFunctionsPDI
+ // above).
+ replaceDirectCallers(G, F);
+ }
}
// If G was internal then we may have replaced all uses of G with F. If so,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34805.119076.patch
Type: text/x-patch
Size: 2732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171015/43c69d8d/attachment.bin>
More information about the llvm-commits
mailing list