OSDN Git Service

[ARM] Promote small global constants to constant pools
authorJames Molloy <james.molloy@arm.com>
Fri, 23 Sep 2016 12:15:58 +0000 (12:15 +0000)
committerJames Molloy <james.molloy@arm.com>
Fri, 23 Sep 2016 12:15:58 +0000 (12:15 +0000)
commite2c1cbe138072e28c6b779bdbc2f19af7ba8d128
tree7b899ac5492d748256f2ba45abd67d2dba142c63
parent91fdd2b6639ae79e0e22406ca6640e544a57d7eb
[ARM] Promote small global constants to constant pools

If a constant is unamed_addr and is only used within one function, we can save
on the code size and runtime cost of an indirection by changing the global's storage
to inside the constant pool. For example, instead of:

      ldr r0, .CPI0
      bl printf
      bx lr
    .CPI0: &format_string
    format_string: .asciz "hello, world!\n"

We can emit:

      adr r0, .CPI0
      bl printf
      bx lr
    .CPI0: .asciz "hello, world!\n"

This can cause significant code size savings when many small strings are used in one
function (4 bytes per string).

This recommit contains fixes for a nasty bug related to fast-isel fallback - because
fast-isel doesn't know about this optimization, if it runs and emits references to
a string that we inline (because fast-isel fell back to SDAG) we will end up
with an inlined string and also an out-of-line string, and we won't emit the
out-of-line string, causing backend failures.

It also contains fixes for emitting .text relocations which made the sanitizer
bots unhappy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282241 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMAsmPrinter.h
lib/Target/ARM/ARMConstantIslandPass.cpp
lib/Target/ARM/ARMConstantPoolValue.cpp
lib/Target/ARM/ARMConstantPoolValue.h
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/ARMMachineFunctionInfo.cpp
lib/Target/ARM/ARMMachineFunctionInfo.h
test/CodeGen/ARM/constantpool-promote-dbg.ll [new file with mode: 0644]
test/CodeGen/ARM/constantpool-promote.ll [new file with mode: 0644]