ARM/ELF: Better codegen for global variable addresses.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 26 Oct 2015 18:23:16 +0000 (18:23 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 26 Oct 2015 18:23:16 +0000 (18:23 +0000)
commit7da5357acaa0e90e6af1a5cbfa88e422d697631c
tree77a5551e73e42cbde6caf7bc2a3d07bbd48d3007
parentd51ca816b5c87c9ba2044d1df7f5180a4c4f789a
ARM/ELF: Better codegen for global variable addresses.

In PIC mode we were previously computing global variable addresses (or GOT
entry addresses) by adding the PC, the PC-relative GOT displacement and
the GOT-relative symbol/GOT entry displacement. Because the latter two
displacements are fixed, we ended up performing one more addition than
necessary.

This change causes us to compute addresses using a single PC-relative
displacement, resulting in a shorter code sequence. This reduces code size
by about 4% in a recent build of Chromium for Android.

As a result of this change we no longer need to compute the GOT base address
in the ARM backend, which allows us to remove the Global Base Reg pass and
SDAG lowering for the GOT.

We also now no longer use the GOT when addressing a symbol which is known
to be defined in the same linkage unit. Specifically, the symbol must have
either hidden visibility or a strong definition in the current module in
order to not use the the GOT.

This is a change from the previous behaviour where we would use the GOT to
address externally visible symbols defined in the same module. I think the
only cases where this could matter are cases involving symbol interposition,
but we don't really support that well anyway.

Differential Revision: http://reviews.llvm.org/D13650

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251322 91177308-0d34-0410-b5e6-96231b3b80d8
19 files changed:
include/llvm/MC/MCExpr.h
lib/MC/MCExpr.cpp
lib/Target/ARM/ARM.h
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMBaseInstrInfo.cpp
lib/Target/ARM/ARMConstantPoolValue.cpp
lib/Target/ARM/ARMConstantPoolValue.h
lib/Target/ARM/ARMFastISel.cpp
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/ARMISelLowering.h
lib/Target/ARM/ARMInstrInfo.cpp
lib/Target/ARM/ARMMachineFunctionInfo.cpp
lib/Target/ARM/ARMMachineFunctionInfo.h
lib/Target/ARM/ARMTargetMachine.cpp
lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
test/CodeGen/ARM/emutls.ll
test/CodeGen/ARM/fast-isel-pic.ll
test/CodeGen/ARM/globals.ll
test/CodeGen/ARM/load-global.ll