[PATCH] D79482: Fix stack clash probing on the tail of dynamic allocation
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 04:49:17 PDT 2020
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: jonpa.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
It's not valid *not* to probe the tail. If the allocation is small, there may be only a tail and no loop, and if it's accumulated it can iteratively increase the stack without probe.
Thanks go to @jonpa for spotting this!
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79482
Files:
llvm/lib/Target/X86/X86FrameLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll
Index: llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll
===================================================================
--- llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll
+++ llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll
@@ -27,6 +27,7 @@
; CHECK-NEXT: .LBB0_3:
; CHECK-NEXT: subq %rax, %rsp
; CHECK-NEXT: movq %rsp, %rax
+; CHECK-NEXT: movq $0, (%rsp)
; CHECK-NEXT: movl $1, 4792(%rax)
; CHECK-NEXT: movl (%rax), %eax
; CHECK-NEXT: movq %rbp, %rsp
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -31618,6 +31618,11 @@
physSPReg)
.addReg(physSPReg)
.addReg(tmpSizeVReg);
+
+ // touch the tail too, as we don't have any information about the context
+ addRegOffset(BuildMI(tailMBB, DL, TII->get(MovMIOpc)), physSPReg, false, 0)
+ .addImm(0);
+
BuildMI(tailMBB, DL, TII->get(TargetOpcode::COPY), MI.getOperand(0).getReg())
.addReg(physSPReg);
Index: llvm/lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86FrameLowering.cpp
+++ llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -273,9 +273,8 @@
// allocation is split in smaller chunks anyway.
if (EmitInlineStackProbe && !InEpilogue) {
- // stack probing may involve looping, and control flow generations is
- // disallowed at this point. Rely to later processing through
- // `inlineStackProbe`.
+ // Delegate stack probing to the `inlineStackProbe` mechanism to avoid
+ // complications.
MachineInstr *Stub = emitStackProbeInlineStub(MF, MBB, MBBI, DL, true);
// Encode the static offset as a metadata attached to the stub.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79482.262340.patch
Type: text/x-patch
Size: 1821 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200506/f954c50f/attachment.bin>
More information about the llvm-commits
mailing list