Index: llvm/lib/Target/X86/X86FrameLowering.cpp =================================================================== --- llvm/lib/Target/X86/X86FrameLowering.cpp +++ llvm/lib/Target/X86/X86FrameLowering.cpp @@ -651,10 +651,13 @@ void X86FrameLowering::inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const { - auto Where = llvm::find_if(PrologMBB, [](MachineInstr &MI) { - return MI.getOpcode() == X86::STACKALLOC_W_PROBING; - }); - if (Where != PrologMBB.end()) { + while (1) { + auto Where = llvm::find_if(PrologMBB, [](MachineInstr &MI) { + return MI.getOpcode() == X86::STACKALLOC_W_PROBING; + }); + if (Where == PrologMBB.end()) + break; + DebugLoc DL = PrologMBB.findDebugLoc(Where); emitStackProbeInline(MF, PrologMBB, Where, DL, true); Where->eraseFromParent(); Index: llvm/test/CodeGen/X86/x86-64-intrcc.ll =================================================================== --- llvm/test/CodeGen/X86/x86-64-intrcc.ll +++ llvm/test/CodeGen/X86/x86-64-intrcc.ll @@ -174,5 +174,23 @@ ret void } +define x86_intrcc void @test_stack_allocation(ptr byval(%struct.interrupt_frame) %frame, i64 %err) #1 { + ; CHECK-LABEL: test_stack_allocation: + ; CHECK: # %bb.0: # %entry + + ; Ensure that STACKALLOC_W_PROBING isn't emitted. + ; CHECK-NOT: # fixed size alloca with probing + ; Ensure that stack space is allocated. + ; CHECK: subq $280, %rsp +entry: + %some_allocation = alloca i64 + ; Call a un-inlineable function to ensure the allocation isn't put in the red + ; zone. + call void @external_function(ptr %some_allocation) + ret void +} + +declare void @external_function(ptr) attributes #0 = { nounwind "frame-pointer"="all" } +attributes #1 = { nounwind "probe-stack"="inline-asm" }