Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
[MergeFuncs] Call removeUsers() prior to unnamed_addr RAUW
Browse files Browse the repository at this point in the history
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346385 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark committed Nov 8, 2018
1 parent dffab3c commit ac6183e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Transforms/IPO/MergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/Transforms/MergeFunc/unnamed-addr-reprocessing.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ac6183e

Please sign in to comment.