This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][SVE] Allow accesses to SVE stack objects to use frame pointer
ClosedPublic

Authored by bsmith on Jan 11 2021, 4:29 AM.

Details

Summary

The layout of the stack frame for SVE means that using the frame pointer
rather than the stack pointer for an access to an SVE stack object
removes the need for an additional add to jump over the non-SVE objects.

Likewise the opposite is true for non-SVE stack objects.

This patch allows for the former to be done by having HasFP return true
in the presence of both SVE and non-SVE stack objects, and also fixes a
minor issue whereby the later would not be done for certain offsets.

Diff Detail

Event Timeline

bsmith created this revision.Jan 11 2021, 4:29 AM
bsmith requested review of this revision.Jan 11 2021, 4:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2021, 4:29 AM
sdesmalen added inline comments.Jan 19 2021, 6:05 AM
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1950

is it worth folding the condition for SVEStackSize into FPOffsetFits above?

// The FP offset will not fit if there is an SVE area in the way.
if (SVEStackSize && FPOffset < 0)
  FPOffsetFits = false;
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
251–253

You should be able to use MFI.isCalleeSavedInfoValid() (instead of having to add this function).

llvm/test/CodeGen/AArch64/sve-frame-registers.ll
2 ↗(On Diff #315758)

Can you amend llvm/test/CodeGen/AArch64/framelayout-sve.mir with these test cases, in favour of having this LLVM IR file?
There should already be existing tests for checking the right base register is used (search for test_address_*)

15 ↗(On Diff #315758)

nit: normally the CHECK lines are all bundled together under the CHECK-LABEL. (that's also what scripts like update_llc_test_checks.py do).

bsmith added inline comments.Jan 19 2021, 9:06 AM
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
251–253

CalleeSavedInfoValid is set before the callee saved stack size is set, hence unfortunately this isn't sufficient. Doing this triggers an assertion:

unsigned int llvm::AArch64FunctionInfo::getCalleeSavedStackSize() const: Assertion `HasCalleeSavedStackSize && "CalleeSavedStackSize has not been calculated"' failed.

Given that the callee saved stack size being set is protected by HasCalleeSavedStackSize I think it makes sense to expose that value.

llvm/test/CodeGen/AArch64/sve-frame-registers.ll
2 ↗(On Diff #315758)

I think it's possible that all of these tests are actually covered already in llvm/test/CodeGen/AArch64/framelayout-sve.mir, perhaps I should just remove these completely?

bsmith updated this revision to Diff 318149.Jan 21 2021, 4:03 AM
  • Remove duplicate tests
  • Some code cleanups as per review comments
sdesmalen added inline comments.Jan 25 2021, 7:44 AM
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
251–253

Are you sure? MFI.setCalleeSavedInfoValid(true) is called in PEI after calling TFI->determineCalleeSaves() which sets HasCalleeSavedStackSize.

bsmith marked an inline comment as done.Jan 26 2021, 6:53 AM
bsmith added inline comments.
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
251–253

You are right about this, I got this backwards. The assertion is actually coming from MIR tests which set setCalleeSavedInfoValid to true in MIRParserImpl::initializeFrameInfo(). So I guess in normal use this isn't a problem, but for MIR tests it can be.

I'm not sure how to approach this one, I still feel like exposing HasCalleeSavedStackSize is the right thing to do though, as that is protecting the thing we are actually querying.

This revision is now accepted and ready to land.Jan 27 2021, 1:51 PM
bsmith closed this revision.Jan 28 2021, 4:43 AM

Committed as rG42635856ed3c. (Forgot to add differential tag in commit message).