This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Async unwind - Fix MTE codegen emitting frame adjustments in a loop
ClosedPublic

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

Details

Summary

When untagging the stack, the compiler may emit a sequence like:

.LBB0_1:
  st2g sp, [sp], #32
  sub x8, x8, #32
  cbnz x8, .LBB0_1
  stg sp, [sp], #16

These stack adjustments cannot be described by CFI instructions.

This patch disables merging of SP update with untagging, i.e. makes the
compiler use an additional scratch register (there should be plenty
available at this point as we are in the epilogue) and generate:

        mov     x9, sp
        mov     x8, #256
        stg     x9, [x9], #16
.LBB0_1:
        sub     x8, x8, #32
        st2g    x9, [x9], #32
        cbnz    x8, .LBB0_1
        add     sp, sp, #272

Merging is disabled only when we need to generate asynchronous unwind
tables.

Diff Detail

Event Timeline

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

It looks like none of the testcases actually generate the loop using an additional scratch register described in the commit message?

chill updated this revision to Diff 393079.Dec 9 2021, 2:30 AM
chill added a comment.Dec 9 2021, 2:32 AM

It looks like none of the testcases actually generate the loop using an additional scratch register described in the commit message?

D'oh, that was the whole point of duplicating stg_alloca17() into stg_alloca18(). Fixed.

Sorry for the delayed review.

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
3554

typo: TryMergeSPUpdate

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
610

Is this an unrelated fix? Are we generating broken code because of this?

chill updated this revision to Diff 399021.Jan 11 2022, 11:01 AM
chill marked an inline comment as done.
chill marked an inline comment as done.Jan 12 2022, 5:58 AM
chill added inline comments.
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
610

We are changing an "ordinary" instruction to a one with a writeback. Without this part we get

*** Bad machine code: Operand should be tied ***
- function:    stg_alloca18
- basic block: %bb.0 entry (0x70c9038)
- instruction: dead early-clobber renamable $x8, dead early-clobber renamable $x9 = STGloop_wback 272, killed $x9 :: (store (s2176) into %ir.a, align 16)
- operand 3:   killed $x9

when running MachineVerifier.

efriedma added inline comments.Jan 26 2022, 10:08 AM
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
592

"but not the operands" needs to be updated.

594

Maybe rename this helper? Not a big deal either way.

602

Minor nit: move the definition of "Op" inside the if statement.

chill updated this revision to Diff 408948.Feb 15 2022, 10:08 AM
chill marked an inline comment as done.
chill marked 3 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 4:23 AM
eugenis accepted this revision.Mar 8 2022, 2:25 PM

LGTM

This revision is now accepted and ready to land.Mar 8 2022, 2:25 PM
chill updated this revision to Diff 417929.Mar 24 2022, 7:33 AM

Rebased.

chill updated this revision to Diff 419191.Mar 30 2022, 9:56 AM
This revision was landed with ongoing or failed builds.Apr 15 2022, 6:03 AM
This revision was automatically updated to reflect the committed changes.