[PATCH] D53262: [MergeFuncs] Call removeUsers() prior to unnamed_addr RAUW

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 14 12:58:52 PDT 2018


nikic created this revision.
nikic added reviewers: jfb, whitequark.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D53262

Files:
  lib/Transforms/IPO/MergeFunctions.cpp
  test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll


Index: test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll
===================================================================
--- /dev/null
+++ 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, as 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
+}
Index: lib/Transforms/IPO/MergeFunctions.cpp
===================================================================
--- lib/Transforms/IPO/MergeFunctions.cpp
+++ lib/Transforms/IPO/MergeFunctions.cpp
@@ -770,6 +770,7 @@
         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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53262.169620.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181014/807c8892/attachment.bin>


More information about the llvm-commits mailing list