[LLVMdev] Removing AvailableExternal values in GlobalDCE (was Re: RFC: ThinLTO Impementation Plan)

Reid Kleckner rnk at google.com
Thu Jun 4 17:33:17 PDT 2015


On Thu, Jun 4, 2015 at 5:17 PM, Teresa Johnson <tejohnson at google.com> wrote:
>
> Agreed. Although I assume you mean invoke the new pass under a
> ThinLTO-only option so that avail extern are not dropped in the
> compile pass before the LTO link?


No, this pass would actually be an improvement to the standard -O2
pipeline. The special case is the regular LTO pass pipeline, which wants to
run GlobalDCE but doesn't want to drop available_externally function
definitions until after linker-stage inlining.

Consider this test case:

declare void @blah()
define i32 @main() {
  call void @foo()
  ret i32 0
}
define available_externally void @foo() noinline {
  call void @bar()
  ret void
}
define linkonce_odr void @bar() noinline {
  call void @blah()
  ret void
}

If I run opt -O2 on this and feed it to llc, it actually generates code for
bar, even though there are no actual references to bar in the final code:

main:                                   # @main
        pushq   %rax
        callq   foo
        xorl    %eax, %eax
        popq    %rdx
        retq

bar:                                    # @bar
        jmp     blah                    # TAILCALL

This corner case happens to come up organically with dllimported classes,
which is why I happened to think of it. :) I'm happy with a flag to
globaldce for LTO and the original patch, honestly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150604/4a59b3f6/attachment.html>


More information about the llvm-dev mailing list