This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Use FP to access the emergency spill slot
ClosedPublic

Authored by thegameg on Apr 6 2018, 2:46 AM.

Details

Summary

In the presence of variable-sized stack objects, we always picked the base pointer when resolving frame indices if it was available.

This makes us hit an assert where we can't reach the emergency spill slot if it's too far away from the base pointer. Since on AArch64 we decide to place the emergency spill slot at the top of the frame, it makes more sense to use FP to access it.

The changes here don't affect only emergency spill slots but all the frame indices. The goal here is to try to choose between FP, BP and SP so that we minimize the offset and avoid scavenging, or worse, asserting when trying to access a slot allocated by the scavenger.

Diff Detail

Event Timeline

thegameg created this revision.Apr 6 2018, 2:46 AM
efriedma added inline comments.Apr 6 2018, 12:27 PM
lib/Target/AArch64/AArch64FrameLowering.cpp
1005

Could this needsStackRealignment check cause problems similar to the bug you're fixing?

1020

How did the !CanUseBP work before this patch?

thegameg added inline comments.Apr 9 2018, 6:43 AM
lib/Target/AArch64/AArch64FrameLowering.cpp
1005

I just looked into this, and in PEI we don't put the emergency spill slot at the top of the frame if we need stack realignment. We put it at the end so the base pointer will be able to reach it and we won't hit this bug.

1020

Before, we would use FP if MFI.hasVarSizedObjects && !CanUseBP. hasBasePointer can return false even if we have var sized objects, and that's only when we can tell that we can reach everything with FP.

efriedma accepted this revision.Apr 9 2018, 2:13 PM

LGTM

This revision is now accepted and ready to land.Apr 9 2018, 2:13 PM
This revision was automatically updated to reflect the committed changes.