This is an archive of the discontinued LLVM Phabricator instance.

LTO: Apply global DCE to ThinLTO modules at LTO opt level 0.
ClosedPublic

Authored by pcc on Oct 31 2017, 5:11 PM.

Details

Summary

This is necessary because DCE is applied to full LTO modules. Without
this change, a reference from a dead ThinLTO global to a dead full
LTO global will result in an undefined reference at link time.

This problem is only observable when --gc-sections is disabled, or
when targeting COFF, as the COFF port of lld requires all symbols to
have a definition even if all references are dead (this is consistent
with link.exe).

This change also adds an EliminateAvailableExternally pass at -O0. This
is necessary to handle the situation on Windows where a non-prevailing
copy of a linkonce_odr function has an SEH filter function; any
such filters must be DCE'd because they will contain a call to the
llvm.localrecover intrinsic, passing as an argument the address of the
function that the filter belongs to, and llvm.localrecover requires
this function to be defined locally.

Fixes PR35142.

Event Timeline

pcc created this revision.Oct 31 2017, 5:11 PM
tejohnson added inline comments.Nov 1 2017, 7:52 AM
llvm/lib/LTO/LTO.cpp
1101

I think it is worth a comment about why we are doing the other summary based optimizations such as internalization at -O0, so someone doesn't go back later and make those conditional.

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
425

Just to ensure I understand correctly - needing to remove the non-prevailing linkonce_odr is in turn due to the change to do internalization/DCE at -O0?

llvm/test/LTO/Resolution/X86/dead-strip-fulllto.ll
21

add a check that we don't have @odr either?

pcc updated this revision to Diff 121148.Nov 1 2017, 10:47 AM
pcc marked 2 inline comments as done.
  • Address review comments
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
425

Yes, otherwise we can end up with a situation like in Inputs/dead-strip-fulllto.ll where odr is keeping dead3 alive. If dead3 contained references to other dead symbols, that would cause an undefined symbol error.

This revision is now accepted and ready to land.Nov 1 2017, 10:52 AM
This revision was automatically updated to reflect the committed changes.
rnk edited edge metadata.Nov 2 2017, 10:01 AM

+1, this should speed up ThinLTO -O0 in addition to being a workaround for the SEH filter function issue. Less code to generate means faster links.