This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Alter the register allocation order for optsize on Thumb2
ClosedPublic

Authored by dmgreen on Dec 21 2018, 9:00 AM.

Details

Summary

Currently in Arm code, we allocate LR first, under the assumption that
it needs to be saved anyway. Unfortunately this has the disadvantage
that it will require any instructions using it to be the longer thumb2
instructions, not the shorter thumb1 ones.

This switches the order when we are optimising for minsize, returning to
the default order so that more lower registers can be used. It can end
up requiring more pushed registers, but on average produces smaller code.

Diff Detail

Repository
rL LLVM

Event Timeline

dmgreen created this revision.Dec 21 2018, 9:00 AM

This isn't the first time this has come up; see https://reviews.llvm.org/D30324 . I guess changing the allocation order for lr, but not ip, makes this version simpler?

Hello

I had not seen that, thanks for pointing to it. Yes, this is a bit simpler, not trying to deal with r12. Just using the default allocation order only gets us so far, but it seems like a simple enough change. I had tried a few different orderings around using r4/r7 before lr, for example, as they are often spilled in pairs, but this seemed to give the best results for the codebases I tried.

I would say that this patch get us a little bit of codesize in many places, adding up to a good overall gain. Compared to all the other codefolding/libcall style changes we might try to make (that would occur in less places), this seems like an easier win for a simple change.

efriedma accepted this revision.Jan 21 2019, 12:38 PM

I guess this is fine as an incremental change. LGTM

lib/Target/ARM/ARMRegisterInfo.td
274 ↗(On Diff #179295)

80 cols.

This revision is now accepted and ready to land.Jan 21 2019, 12:38 PM
This revision was automatically updated to reflect the committed changes.