[llvm] r350939 - [MergeFunc] Erase unused duplicate functions if they are discardable
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 11 10:50:46 PST 2019
This caused buildbot failures in clang/test/CodeGenCXX/merge-functions.cpp. I should have a fix momentarily.
vedant
> On Jan 11, 2019, at 9:56 AM, Vedant Kumar via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: vedantk
> Date: Fri Jan 11 09:56:35 2019
> New Revision: 350939
>
> URL: http://llvm.org/viewvc/llvm-project?rev=350939&view=rev
> Log:
> [MergeFunc] Erase unused duplicate functions if they are discardable
>
> MergeFunc only deletes unused duplicate functions if they have local
> linkage, but it should be safe to relax this to any "discardable if
> unused" linkage type.
>
> Differential Revision: https://reviews.llvm.org/D56574
>
> Modified:
> llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
> llvm/trunk/test/Transforms/MergeFunc/linkonce_odr.ll
>
> Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=350939&r1=350938&r2=350939&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Fri Jan 11 09:56:35 2019
> @@ -845,7 +845,7 @@ void MergeFunctions::mergeTwoFunctions(F
> // If G was internal then we may have replaced all uses of G with F. If so,
> // stop here and delete G. There's no need for a thunk. (See note on
> // MergeFunctionsPDI above).
> - if (G->hasLocalLinkage() && G->use_empty() && !MergeFunctionsPDI) {
> + if (G->isDiscardableIfUnused() && G->use_empty() && !MergeFunctionsPDI) {
> G->eraseFromParent();
> ++NumFunctionsMerged;
> return;
>
> Modified: llvm/trunk/test/Transforms/MergeFunc/linkonce_odr.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeFunc/linkonce_odr.ll?rev=350939&r1=350938&r2=350939&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/MergeFunc/linkonce_odr.ll (original)
> +++ llvm/trunk/test/Transforms/MergeFunc/linkonce_odr.ll Fri Jan 11 09:56:35 2019
> @@ -1,4 +1,4 @@
> -; RUN: opt -S -mergefunc < %s | FileCheck %s
> +; RUN: opt -S -mergefunc < %s | FileCheck %s -implicit-check-not=funC
>
> ; Replacments should be totally ordered on the function name.
> ; If we don't do this we can end up with one module defining a thunk for @funA
> @@ -15,6 +15,13 @@
> ; CHECK-NEXT: tail call i32 @funA(i32 %0, i32 %1)
> ; CHECK-NEXT: ret
>
> +define linkonce_odr i32 @funC(i32 %x, i32 %y) {
> + %sum = add i32 %x, %y
> + %sum2 = add i32 %x, %sum
> + %sum3 = add i32 %x, %sum2
> + ret i32 %sum3
> +}
> +
> define linkonce_odr i32 @funB(i32 %x, i32 %y) {
> %sum = add i32 %x, %y
> %sum2 = add i32 %x, %sum
> @@ -28,3 +35,8 @@ define linkonce_odr i32 @funA(i32 %x, i3
> %sum3 = add i32 %x, %sum2
> ret i32 %sum3
> }
> +
> +; This creates a use of @funB, preventing -mergefunc from deleting it.
> +; @funC, however, can safely be deleted as it has no uses, and is discardable
> +; if unused.
> + at take_addr_of_funB = global i8* bitcast (i32 (i32, i32)* @funB to i8*)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list