This is an archive of the discontinued LLVM Phabricator instance.

AArch64: Use a callee save registers for swiftself parameters
ClosedPublic

Authored by MatzeB on Apr 7 2016, 2:39 PM.

Details

Summary

It is very likely that the swiftself parameter is alive throughout most
functions. Putting it into a callee save register should avoid spills
for callers with only a few extra spills in callees.

Currently the generated code is correct but unnecessarily spills and
reloads arguments passed in callee save registers, I will address this
in upcoming patches.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 52956.Apr 7 2016, 2:39 PM
MatzeB retitled this revision from to AArch64: Use a callee save registers for swiftself parameters.
MatzeB updated this object.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
manmanren edited edge metadata.Apr 7 2016, 8:58 PM

Thanks for cleaning up the testing case!

Manman

lib/Target/AArch64/AArch64FrameLowering.cpp
704

So if isReturnAddressTaken is true, LRLiveIn will be true as well?
The original check of !(LRLiveIn && MF.getFrameInfo()->isReturnAddressTaken()) is equivalent to !LRLiveIn?

test/CodeGen/AArch64/swiftself.ll
59

Are these the spills and reloads you mentioned in the summary?

Currently the generated code is correct but unnecessarily spills and
reloads arguments passed in callee save registers, I will address this
in upcoming patches.

MatzeB added inline comments.Apr 7 2016, 9:08 PM
lib/Target/AArch64/AArch64FrameLowering.cpp
704

If LR is used to access the return address, then isLiveIn(LR) will be true, which is fine. The new code is slightly more allowing since it does not explicitly check for isReturnAddressTaken() anymore. However I don't see how this could ever be marked in otherwise. (Also missing kill flags are not a correctness problem but can just result in worse register scavenging results, though with the reserved LR register this is not an issue anyway).

test/CodeGen/AArch64/swiftself.ll
59

Yep that is what I mentioned, I should probably remove them from the test, as that is not what we want to test here.
And indeed we should find a way to avoid them longer term (I've seen that you worked on SplitCSR before which can be adapted to this case I assume...)

MatzeB added a comment.Apr 7 2016, 9:23 PM

I just realized that there are radars that propose x19 to be used for swifterror. We can of course change the register. The important parts are the bits that allow to pass values in callee saved registers.

MatzeB updated this revision to Diff 53045.Apr 8 2016, 11:05 AM
MatzeB edited edge metadata.

Update testcase to be in line with the other swiftself patches.

MatzeB updated this revision to Diff 53071.Apr 8 2016, 1:03 PM

Add comment that omitting the kill flag is conservatively correct.

MatzeB updated this revision to Diff 53351.Apr 11 2016, 7:00 PM

Update patch: We have to tail calls when the argument passed in the swiftself of the callee is not the same as the swift self of the caller.

MatzeB updated this revision to Diff 53357.Apr 11 2016, 8:43 PM

Move from X19 to X20 to avoid clash with swifterror parameter.

qcolombet edited edge metadata.Apr 12 2016, 5:24 PM

Hi Matthias,

Same comment as http://reviews.llvm.org/D18902 + some questions on the test cases.

Cheers,
-Quentin

test/CodeGen/AArch64/swiftself.ll
40

Is it intended that we just check the label for O0?

49

Ditto.

59

Check that addr1 is properly copied into x20 from x1?

t.p.northover edited edge metadata.Apr 13 2016, 2:10 PM

The AArch64 changes look fine to me too. I'll leave it to you and Quentin to sort out the best tests, I don't feel too strongly either way.

Tim.

MatzeB marked 7 inline comments as done.Apr 13 2016, 2:45 PM

Thanks for the review.

test/CodeGen/AArch64/swiftself.ll
40

The label is always checked.
The rest of the check makes sure that we can indeed create code with no additional mov instructions for the paramaters, -O0 codegen just doesn't optimize enough for it and is left out.

49

Ditto (only the optimized codegen performs tail call opts which we want to test for).

MatzeB accepted this revision.Apr 15 2016, 3:29 PM
MatzeB added a reviewer: MatzeB.
MatzeB marked 2 inline comments as done.

This landed as r266251, accept & close.

This revision is now accepted and ready to land.Apr 15 2016, 3:29 PM
MatzeB closed this revision.Apr 15 2016, 3:29 PM

This landed as r266251, accept & close.