This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Async unwind - Adjust unwind info in AArch64LoadStoreOptimizer
ClosedPublic

Authored by chill on Nov 24 2021, 10:35 AM.

Details

Summary

The AArch64LoadStoreOptimnizer pass may merge a register
increment/decrement with a following memory operation. In doing so, it
may break CFI by moving a stack pointer adjustment past the CFI
instruction that described *that* adjustment.

This patch fixes this issue by moving said CFI instruction after the
merged instruction, where the SP increment/decrement actually takes
place.

Diff Detail

Event Timeline

chill created this revision.Nov 24 2021, 10:35 AM
chill requested review of this revision.Nov 24 2021, 10:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2021, 10:35 AM

This could use a big comment explaining that AArch64LoadStoreOpt can run after PEI, and what that means in terms of the invariants we rely on, and the invariants we need to uphold to preserve unwind info. I can see what this patch is doing, but it's not obvious this is a comprehensive solution. Are sp adjustments the only CFI info we need to update? Does it matter if the load/store we're modifying already has a CFI directive attached to it?

chill updated this revision to Diff 393070.Dec 9 2021, 1:45 AM
chill added a comment.Dec 9 2021, 2:10 AM

This could use a big comment explaining that AArch64LoadStoreOpt can run after PEI, and what that means in terms of the invariants we rely on, and the invariants we need to uphold to preserve unwind info. I can see what this patch is doing, but it's not obvious this is a comprehensive solution. Are sp adjustments the only CFI info we need to update?

It's entirely possible this is not a comprehensive solution and I certainly wouldn't claim it was. I just have not noticed or been able to think of any other cases.

One possible thing is merging an SP update to a preceding load/store - if it jumps over a few unrelated instructions the CFA offset would be incorrect for these few instructions.
Such merging is done during epilogue emission, so CFI instructions are emitted accordingly and I couldn't steer the compiler into leaving that to load/store optimiser, where it
wold break the unwind info (and by "break" I mean a small degradation in the user experience when debugging or a slight decline in the precision of sampling profilers, certainly
nothing the affects code correctness).

Does it matter if the load/store we're modifying already has a CFI directive attached to it?

I shouldn't. It would at most create some redundancy if the load/store already wrote-back to SP and had a .cfi_def_cfa_offset, or .cfi_def_cfa immediately following it.

chill updated this revision to Diff 399017.Jan 11 2022, 10:40 AM
efriedma accepted this revision.Jan 11 2022, 11:55 AM

LGTM with one minor comment

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
1774

Maybe assert MI is an add or subtract, to make clear what cases you're expecting to handle here?

This revision is now accepted and ready to land.Jan 11 2022, 11:55 AM
chill marked an inline comment as done.Jan 27 2022, 9:57 AM
chill added inline comments.
llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
1774

There are already asserts like this at lines 1794-1795 (just a little below this comment), I think they ought to do.

efriedma added inline comments.Jan 27 2022, 10:46 AM
llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
1774

It's more of a documentation this; I'm a little worried someone in the future will assume this helper is more general than it actually is.

Not a big deal either way.

chill updated this revision to Diff 408938.Feb 15 2022, 9:47 AM
chill marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 8:12 AM
chill updated this revision to Diff 417927.Mar 24 2022, 7:33 AM

Rebased

chill updated this revision to Diff 419190.Mar 30 2022, 9:55 AM
This revision was landed with ongoing or failed builds.Apr 13 2022, 9:25 AM
This revision was automatically updated to reflect the committed changes.

Looks like this was reverted, just posting this link to Linaro's TCWG's CI failure report:
https://lore.kernel.org/llvm/22774472.13865.1649959991991@jenkins.jenkins/

This revision is now accepted and ready to land.Apr 15 2022, 4:17 AM
chill planned changes to this revision.Apr 15 2022, 4:17 AM
chill updated this revision to Diff 423111.Apr 15 2022, 8:03 AM

Fixed a bootstrap failure, there was a missing check for end iterator.

This revision is now accepted and ready to land.Apr 15 2022, 8:03 AM
This revision was landed with ongoing or failed builds.Apr 18 2022, 4:11 AM
This revision was automatically updated to reflect the committed changes.