llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28k stars 11.56k forks source link

ThinLTO doesn't apply interprocedural GlobalDCE optimization #32978

Closed llvmbot closed 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 33631
Resolution INVALID
Resolved on Jul 03, 2017 09:27
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

// a.c int jj = 10;

int x() { return jj; }

int f(int x) { return x + 1; }

// b.c

extern int f(int);

int main(void) { return 1; }

///////////////////

=== THINLTO ===

$ ../build/bin/clang a.c b.c --for-linker=-mllvm --for-linker=-stats -flto=thin \ -fuse-ld=lld -o out &>&1 | grep globaldce

nothing

=== LTO ===

$ ../build/bin/clang a.c b.c --for-linker=-mllvm --for-linker=-stats -flto \ -fuse-ld=lld -o out &>&1 | grep globaldce 2 globaldce - Number of functions removed 1 globaldce - Number of global variables removed

llvmbot commented 7 years ago

Great, thanks for the confirmation! I think this one can be closed.

llvmbot commented 7 years ago

We do a round of dead-stripping on the index during the thin link, then mark for internalization any global values not reached by anything exported from the binary, which means they will be internalized and then deleted by the ThinLTO backends. Can you check what the final code looks like in the ThinLTO case, and confirm that is happening? You might need to compile with -O1 or up to get the full optimization pipeline to kick in BTW.

Yup - this does happen - the final binaries are stripped of unused functions/globals. Should I delete this bug now, since the pass is unnecessary?

llvmbot commented 7 years ago

We do a round of dead-stripping on the index during the thin link, then mark for internalization any global values not reached by anything exported from the binary, which means they will be internalized and then deleted by the ThinLTO backends. Can you check what the final code looks like in the ThinLTO case, and confirm that is happening? You might need to compile with -O1 or up to get the full optimization pipeline to kick in BTW.