[X86][ELF] Prefer to lower MC_GlobalAddress operands to .Lfoo$local
authorFangrui Song <maskray@google.com>
Wed, 22 Jan 2020 20:27:17 +0000 (12:27 -0800)
committerFangrui Song <maskray@google.com>
Fri, 31 Jan 2020 01:52:35 +0000 (17:52 -0800)
commit5b22bcc2b70d82c73ce5428170dcc2038a729d74
tree712e97c1d570cafaf38d7507080ae606b765728f
parent980517b3530ffb7faa1a23fdc007d78f5b45ae3c
[X86][ELF] Prefer to lower MC_GlobalAddress operands to .Lfoo$local

For a MC_GlobalAddress reference to a dso_local external GlobalValue with a definition, emit .Lfoo$local to avoid a relocation.

-fno-pic and -fpie can infer dso_local but -fpic cannot.  In the future,
we can explore the possibility of inferring dso_local with -fpic. As the
description of D73228 says, LLVM's existing IPO optimization behaviors
(like -fno-semantic-interposition) and a previous assembly behavior give
us enough license to be aggressive here.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D73230
llvm/lib/Target/X86/X86MCInstLower.cpp
llvm/test/CodeGen/X86/code-model-elf.ll
llvm/test/CodeGen/X86/emutls.ll
llvm/test/CodeGen/X86/fold-add-pcrel.ll
llvm/test/CodeGen/X86/linux-preemption.ll
llvm/test/CodeGen/X86/oddsubvector.ll
llvm/test/CodeGen/X86/pr38795.ll
llvm/test/CodeGen/X86/tailcallpic1.ll
llvm/test/CodeGen/X86/tailcallpic3.ll
llvm/test/CodeGen/X86/tailccpic1.ll
llvm/test/CodeGen/X86/tls.ll