This is an archive of the discontinued LLVM Phabricator instance.

ARM: Use a callee save register for the swiftself parameter.
ClosedPublic

Authored by MatzeB on Apr 8 2016, 10:51 AM.

Details

Summary

It is very likely that the swiftself parameter is alive throughout most
functions function so putting it into a callee save register should
avoid spills for the callers with only a minimum amount of extra spills
in the 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.

This also adds a missing check that for tail calls the preserved value
of the caller must be the same as the callees parameter.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 53039.Apr 8 2016, 10:51 AM
MatzeB retitled this revision from to ARM: Use a callee save register for the swiftself parameter..
MatzeB updated this object.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
mgrang added a subscriber: mgrang.Apr 8 2016, 11:00 AM
mgrang added inline comments.
test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53039)

We can get rid of --check-prefix=CHECK.

MatzeB updated this revision to Diff 53044.Apr 8 2016, 11:04 AM

Remove unnecessary --check-prefix.

rengolin added inline comments.Apr 8 2016, 11:12 AM
lib/Target/ARM/ARMFrameLowering.cpp
914 ↗(On Diff #53039)

Why not just make:

bool isKill = !MF.getRegInfo().isLiveIn(Reg);
t.p.northover added inline comments.Apr 8 2016, 11:14 AM
test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53044)

Why? All labels are under CHECK; it's a fairly common FileCheck idiom to have a shared check-prefix and a run-specific one to save duplication.

But I think there actually is an issue here: OPT != CHECK-OPT.

t.p.northover added inline comments.Apr 8 2016, 11:15 AM
test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53044)

Sorry, I was looking at a newer diff. You were right about the original. I think OPT is still problematic though.

MatzeB updated this revision to Diff 53046.Apr 8 2016, 11:16 AM

Avoid extra isKill variable

MatzeB updated this revision to Diff 53049.Apr 8 2016, 11:19 AM
MatzeB marked 3 inline comments as done.

Fix wrong "OPT:" check lines in test.

qcolombet added inline comments.Apr 8 2016, 11:38 AM
lib/Target/ARM/ARMFrameLowering.cpp
914 ↗(On Diff #53049)

Because if the register is live we *must not* add it into the live-in.

925 ↗(On Diff #53049)

Same comment as x86: conservatively correct.

MatzeB updated this revision to Diff 53068.Apr 8 2016, 12:57 PM

Add note that omitting a kill flag is correct.

rengolin added inline comments.Apr 8 2016, 1:04 PM
lib/Target/ARM/ARMFrameLowering.cpp
914 ↗(On Diff #53068)

yeah, I meant it as a duplication. :)

test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53068)

The CHECK prefix is still there... already assumed by default.

MatzeB marked an inline comment as done.Apr 8 2016, 1:06 PM
MatzeB added inline comments.
lib/Target/ARM/ARMFrameLowering.cpp
914 ↗(On Diff #53046)

I found the codes intention is clearer if the if() condition looks at the live-in not at something called isKill. What about this new version that drops the isKill variable instead?

test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53068)
static void AddCheckPrefixIfNeeded() {
  if (CheckPrefixes.empty())
    CheckPrefixes.push_back("CHECK");
}

It is only default if you do not add any other check-prefixes.

rengolin added inline comments.Apr 8 2016, 1:10 PM
lib/Target/ARM/ARMFrameLowering.cpp
914 ↗(On Diff #53068)

looks good

test/CodeGen/ARM/swiftself.ll
2 ↗(On Diff #53068)

Hum, you're right... I assumed it always did... :(

MatzeB updated this revision to Diff 53353.Apr 11 2016, 7:56 PM
MatzeB updated this object.
MatzeB marked an inline comment as done.

Add check that for tail calls the preserved value of the caller is the same as the callees parameter.

MatzeB updated this revision to Diff 53359.Apr 11 2016, 8:46 PM

Consistently add SwiftSelf support to all calling conventions that support SwiftError.

rengolin added inline comments.Apr 12 2016, 11:09 AM
lib/Target/ARM/ARMISelLowering.cpp
2225 ↗(On Diff #53359)

This part seems oddly formatted...

MatzeB updated this revision to Diff 53434.Apr 12 2016, 11:15 AM

Replace sneaky tabs with spaces.

rengolin accepted this revision.Apr 12 2016, 12:20 PM
rengolin added a reviewer: rengolin.

Right, this looks good to me, but I think it should go together with the AArch64 changes.

This revision is now accepted and ready to land.Apr 12 2016, 12:20 PM
qcolombet edited edge metadata.Apr 12 2016, 5:29 PM

Hi Matthias,

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

Cheers,
-Quentin

test/CodeGen/ARM/swiftself.ll
38 ↗(On Diff #53434)

No checks for O0?

48 ↗(On Diff #53434)

No checks for O0 and OPT alone?

MatzeB marked 4 inline comments as done.Apr 13 2016, 2:35 PM

Thanks for the reviews.

test/CodeGen/ARM/swiftself.ll
38 ↗(On Diff #53434)

This checks whether we can indeed generate code without any additional movs between the calls. The O0 codegen does not optimize enough for that so there is nothing to test.

48 ↗(On Diff #53434)

This checks that tail call optimization does indeed happen when the params are the same, O0 codegen does not perform tailcall opts, "armv7-apple-ios" also has tailcalls disabled so I introduced a new TAILCALL prefix for all target where it does happen.

This revision was automatically updated to reflect the committed changes.