This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][SVE] Only fold frame indexes referencing SVE objects into SVE loads/stores
ClosedPublic

Authored by bsmith on Apr 26 2022, 8:08 AM.

Details

Summary

Currently we always fold frame indexes into SVE load/store instructions,
however these instructions can only encode VL scaled offests. This means
that when we are accessing a fixed length stack object with these
instructions, the folded in frame index gets pulled back out during frame
lowering. This can cause issues when we have no spare registers and no
emergency spill slot.

Rather than causing issues like this, don't fold in frame indexes that
reference fixed length objects.

Fixes: #55041

Diff Detail

Event Timeline

bsmith created this revision.Apr 26 2022, 8:08 AM
Herald added a project: Restricted Project. · View Herald Transcript
bsmith requested review of this revision.Apr 26 2022, 8:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 8:08 AM

Is FrameIndex 0 actually reliably located in a position that doesn't have an offset? That seems unlikely to me, especially if variable-size allocation becomes involved.

Alternatively, we could fix the code that decides whether we need an emergency spill slot. But I guess there's not really much point to attempting to fold the frame indexes in the first place.

Is FrameIndex 0 actually reliably located in a position that doesn't have an offset? That seems unlikely to me, especially if variable-size allocation becomes involved.

Hm, you might be right. It seems a shame to regress cases where the index would be zero, but I'm not sure there is way to tell at this point if the offset will resolve to zero?

Alternatively, we could fix the code that decides whether we need an emergency spill slot. But I guess there's not really much point to attempting to fold the frame indexes in the first place.

I considered that, the issue though is finding the correct condition to do this in without being far too conservative, I think you'd have to do it by traversing the function finding all SVE load/stores and checking what they access, which doesn't seem very nice for an issue we are creating for ourselves.

Is FrameIndex 0 actually reliably located in a position that doesn't have an offset? That seems unlikely to me, especially if variable-size allocation becomes involved.

Hm, you might be right. It seems a shame to regress cases where the index would be zero, but I'm not sure there is way to tell at this point if the offset will resolve to zero?

Alternatively, we could fix the code that decides whether we need an emergency spill slot. But I guess there's not really much point to attempting to fold the frame indexes in the first place.

I considered that, the issue though is finding the correct condition to do this in without being far too conservative, I think you'd have to do it by traversing the function finding all SVE load/stores and checking what they access, which doesn't seem very nice for an issue we are creating for ourselves.

Thinking about this some more, in the interest of not regressing and given this isn't a correctness issue, perhaps we can leave it like this and 'assume' frame index zero has a zero offset, if it is not it will just get pulled back out like it does now (hence no correctness issue), it just may still be possible (although probably incredibly hard) to produce a crash due to lack of emergency spill slot. If it does turn out to be an issue still we can always come back and remove this assumption if necessary.

bsmith updated this revision to Diff 425510.Apr 27 2022, 6:55 AM
  • Update test to use update_llc_test_checks.py script

I'm inclined to agree given this patch is more mitigation rather than an actual fix. Is it not possible to include a minimised version of the original crashing test case? just as a no crash test. I ask because otherwise somebody could easily remove this mitigation without realising the mistake.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
5105

I know we have the if (N.getOpcode() != ISD::ADD) test below but I think it's better to have an explicit return false for invalid values for FI.

bsmith updated this revision to Diff 425519.Apr 27 2022, 7:52 AM
  • Add testcase protecting original issue
  • Add explict false return for invalid frame index
Matt added a subscriber: Matt.Apr 27 2022, 11:07 AM
paulwalker-arm accepted this revision.Apr 27 2022, 4:03 PM
This revision is now accepted and ready to land.Apr 27 2022, 4:03 PM
This revision was landed with ongoing or failed builds.May 3 2022, 3:03 AM
This revision was automatically updated to reflect the committed changes.