[llvm] a07787c - [AArch64] Exclude instructions after setting the FP from SEH prologues

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 02:37:26 PDT 2022


Author: Martin Storsjö
Date: 2022-10-12T12:36:21+03:00
New Revision: a07787c9a50c046e45921dd665f5a53a752bbc31

URL: https://github.com/llvm/llvm-project/commit/a07787c9a50c046e45921dd665f5a53a752bbc31
DIFF: https://github.com/llvm/llvm-project/commit/a07787c9a50c046e45921dd665f5a53a752bbc31.diff

LOG: [AArch64] Exclude instructions after setting the FP from SEH prologues

After setting up the FP, the rest of the prologue doesn't need to
be replayed for unwinding the stack frame.

This allows reverting the functional parts of
2f7fbf837625267193351cc334e506a3a9161958 (but fixing inconsistent
duplicate setting of HasWinCFI).

Differential Revision: https://reviews.llvm.org/D135686

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
    llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
    llvm/test/CodeGen/AArch64/wineh-align-stack.ll
    llvm/test/CodeGen/AArch64/wineh-frame6.mir
    llvm/test/CodeGen/AArch64/wineh-try-catch.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index b1776f027e4e..e89ddf3d0b4a 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -1603,6 +1603,13 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
       emitFrameOffset(MBB, MBBI, DL, AArch64::FP, AArch64::SP,
                       StackOffset::getFixed(FPOffset), TII,
                       MachineInstr::FrameSetup, false, NeedsWinCFI, &HasWinCFI);
+      if (NeedsWinCFI && HasWinCFI) {
+        BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_PrologEnd))
+            .setMIFlag(MachineInstr::FrameSetup);
+        // After setting up the FP, the rest of the prolog doesn't need to be
+        // included in the SEH unwind info.
+        NeedsWinCFI = false;
+      }
     }
     if (EmitCFI) {
       // Define the current CFA rule to use the provided FP.

diff  --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 638851cb6a8f..171182050d2a 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -4335,6 +4335,8 @@ static void emitFrameOffsetAdj(MachineBasicBlock &MBB,
       int Imm = (int)(ThisVal << LocalShiftSize);
       if ((DestReg == AArch64::FP && SrcReg == AArch64::SP) ||
           (SrcReg == AArch64::FP && DestReg == AArch64::SP)) {
+        if (HasWinCFI)
+          *HasWinCFI = true;
         if (Imm == 0)
           BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_SetFP)).setMIFlag(Flag);
         else
@@ -4344,16 +4346,13 @@ static void emitFrameOffsetAdj(MachineBasicBlock &MBB,
         assert(Offset == 0 && "Expected remaining offset to be zero to "
                               "emit a single SEH directive");
       } else if (DestReg == AArch64::SP) {
+        if (HasWinCFI)
+          *HasWinCFI = true;
         assert(SrcReg == AArch64::SP && "Unexpected SrcReg for SEH_StackAlloc");
         BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_StackAlloc))
             .addImm(Imm)
             .setMIFlag(Flag);
-      } else {
-        BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
-            .setMIFlag(Flag);
       }
-      if (HasWinCFI)
-        *HasWinCFI = true;
     }
 
     SrcReg = TmpReg;

diff  --git a/llvm/test/CodeGen/AArch64/wineh-align-stack.ll b/llvm/test/CodeGen/AArch64/wineh-align-stack.ll
index 0b174a08231c..ddb0ab1e5952 100644
--- a/llvm/test/CodeGen/AArch64/wineh-align-stack.ll
+++ b/llvm/test/CodeGen/AArch64/wineh-align-stack.ll
@@ -17,11 +17,6 @@ declare dso_local void @other(ptr noundef)
 ; CHECK-NEXT: .seh_save_fplr_x 16
 ; CHECK-NEXT: mov x29, sp
 ; CHECK-NEXT: .seh_set_fp
+; CHECK-NEXT: .seh_endprologue
 ; CHECK-NEXT: sub x9, sp, #80
-; CHECK-NEXT: .seh_nop
 ; CHECK-NEXT: and sp, x9, #0xffffffffffffffe0
-; CHECK-NEXT: .seh_stackalloc 80
-; CHECK-NEXT: .seh_endprologue
-
-; FIXME: Ideally, the SEH prologue wouldn't include the stack realigning
-; instructions at all, but it's enough to end the prologue after .seh_set_fp.

diff  --git a/llvm/test/CodeGen/AArch64/wineh-frame6.mir b/llvm/test/CodeGen/AArch64/wineh-frame6.mir
index 535d805d0308..913f12202c2b 100644
--- a/llvm/test/CodeGen/AArch64/wineh-frame6.mir
+++ b/llvm/test/CodeGen/AArch64/wineh-frame6.mir
@@ -7,9 +7,8 @@
 # CHECK-NEXT: frame-setup SEH_SaveFPLR_X -16
 # CHECK-NEXT: $fp = frame-setup ADDXri $sp, 0, 0
 # CHECK-NEXT: frame-setup SEH_SetFP
-# CHECK-NEXT: $sp = frame-setup SUBXri $sp, 32, 0
-# CHECK-NEXT: frame-setup SEH_StackAlloc 32
 # CHECK-NEXT: frame-setup SEH_PrologEnd
+# CHECK-NEXT: $sp = frame-setup SUBXri $sp, 32, 0
 # CHECK:      frame-destroy SEH_EpilogStart
 # CHECK-NEXT: $sp = frame-destroy ADDXri $fp, 0, 0
 # CHECK-NEXT: frame-destroy SEH_SetFP

diff  --git a/llvm/test/CodeGen/AArch64/wineh-try-catch.ll b/llvm/test/CodeGen/AArch64/wineh-try-catch.ll
index 7de7d60b8cab..e60c7b97c4e7 100644
--- a/llvm/test/CodeGen/AArch64/wineh-try-catch.ll
+++ b/llvm/test/CodeGen/AArch64/wineh-try-catch.ll
@@ -85,8 +85,6 @@
 
 ; UNWIND: Function: ?func@@YAHXZ (0x0)
 ; UNWIND: Prologue [
-; UNWIND-NEXT: ; nop
-; UNWIND-NEXT: ; sub sp, #624
 ; UNWIND-NEXT: ; add fp, sp, #32
 ; UNWIND-NEXT: ; stp x29, x30, [sp, #32]
 ; UNWIND-NEXT: ; str x28, [sp, #24]


        


More information about the llvm-commits mailing list