Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

ThinLTO doesn't apply interprocedural ConstMerge optimization #32602

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR33630
Status NEW
Importance P enhancement
Reported by Charles Saternos (charles.saternos@gmail.com)
Reported on 2017-06-28 12:45:28 -0700
Last modified on 2017-06-28 16:00:26 -0700
Version trunk
Hardware PC Linux
CC ditaliano@apple.com, llvm-bugs@lists.llvm.org, tejohnson@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
LTO will apply the Constant Merging pass, but ThinLTO can't apply this
optimization right now.

Test case:

// a.c
const char *x = "blah";

// b.c
#include <stdio.h>

extern const char *x;
const char *b = "blah";

int main(void) {
  puts(x);
  puts(b);
}

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

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

# nothing

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

  1 constmerge     - Number of global constants merged
Quuxplusone commented 7 years ago

Is this actually important? The strings will get merged by the linker.