[MergeFunctions] Fix merging of small weak functions
authorwhitequark <whitequark@whitequark.org>
Tue, 15 May 2018 11:31:07 +0000 (11:31 +0000)
committerwhitequark <whitequark@whitequark.org>
Tue, 15 May 2018 11:31:07 +0000 (11:31 +0000)
commit8f0ab258bd9701c755946890331ccada29b781b7
tree8dc8a53d4fe6bf7a7e97a7045c7b59e99d3afee6
parentce5d3d657a25a04331b8a66798b06cd602bf3c4f
[MergeFunctions] Fix merging of small weak functions

When two interposable functions are merged, we cannot replace
uses and have to emit calls to a common internal function. However,
writeThunk() will not actually emit a thunk if the function is too
small. This leaves us in a broken state where mergeTwoFunctions
already rewired the functions, but writeThunk doesn't do anything.

This patch changes the implementation so that:

 * writeThunk() does just that.
 * The direct replacement of calls is moved into mergeTwoFunctions()
   into the non-interposable case only.
 * isThunkProfitable() is extracted and will be called for
   the non-iterposable case always, and in the interposable case
   only if uses are still left after replacement.

This issue has been introduced in https://reviews.llvm.org/D34806,
where the code for checking thunk profitability has been moved.

Differential Revision: https://reviews.llvm.org/D46804

Reviewed By: whitequark

llvm-svn: 332342
llvm/lib/Transforms/IPO/MergeFunctions.cpp
llvm/test/Transforms/MergeFunc/weak-small.ll [new file with mode: 0644]