[PATCH] D135101: [AArch64] Add missing SEH_Nop when aligning the stack
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 13:43:00 PDT 2022
mstorsjo created this revision.
mstorsjo added reviewers: efriedma, zzheng, sdesmalen.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: LLVM.
This makes sure that the instructions of the prologue matches the
SEH opcodes.
Also remove a couple redundant cases of setting HasWinCFI; it was
already set unconditionally after the conditional cases.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135101
Files:
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/test/CodeGen/AArch64/wineh-align-stack.ll
Index: llvm/test/CodeGen/AArch64/wineh-align-stack.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/wineh-align-stack.ll
@@ -0,0 +1,24 @@
+; RUN: llc < %s -mtriple=aarch64-windows | FileCheck %s
+
+define dso_local void @func() {
+entry:
+ %buf = alloca [64 x i8], align 32
+ %arraydecay = getelementptr inbounds [64 x i8], ptr %buf, i64 0, i64 0
+ call void @other(ptr noundef %arraydecay)
+ ret void
+}
+
+declare dso_local void @other(ptr noundef)
+
+; CHECK-LABEL: func:
+; CHECK-NEXT: .seh_proc func
+; CHECK-NEXT: // %bb.0:
+; CHECK-NEXT: stp x29, x30, [sp, #-16]!
+; CHECK-NEXT: .seh_save_fplr_x 16
+; CHECK-NEXT: mov x29, sp
+; CHECK-NEXT: .seh_set_fp
+; 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
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -4334,8 +4334,6 @@
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
@@ -4345,12 +4343,13 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135101.464797.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221003/4aabb3ce/attachment.bin>
More information about the llvm-commits
mailing list