This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Promote small global constants to constant pools
ClosedPublic

Authored by jmolloy on Sep 5 2016, 8:39 AM.

Details

Summary

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).

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy updated this revision to Diff 70335.Sep 5 2016, 8:39 AM
jmolloy retitled this revision from to [ARM] Promote small global constants to constant pools.
jmolloy updated this object.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.
joerg added a subscriber: joerg.Sep 5 2016, 9:14 AM

Should PIC be factored in here as well? I think I would like to see testing for that at least.

olista01 added inline comments.Sep 5 2016, 9:53 AM
lib/Target/ARM/ARMISelLowering.cpp
2890

Would it also be worth doing this for very small constants with multiple uses? If the constant is no larger than a pointer then this won't increase code size, and should help performance by removing a layer of indirection.

test/CodeGen/ARM/constantpool-promote.ll
43

Missing CHECK lines?

jmolloy updated this revision to Diff 70387.Sep 6 2016, 4:55 AM
jmolloy marked an inline comment as done.

Hi Oliver and Joerg,

Thanks for the comments. I've fixed the issues you noticed Oliver, and Joerg I agree this should work for PIC modes so I've enabled that and tested it.

Cheers,

James

olista01 accepted this revision.Sep 12 2016, 5:38 AM
olista01 edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 12 2016, 5:38 AM
jmolloy closed this revision.Sep 12 2016, 6:51 AM

Thanks Oliver, r281213.

lib/Target/ARM/ARMISelLowering.cpp
2890

Good point, I agree.