Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #95 from dotdash/stack_pop
Browse files Browse the repository at this point in the history
[X86] Don't clobber reserved registers with stack adjustments
  • Loading branch information
alexcrichton authored Nov 7, 2017
2 parents 86c7a99 + a62844c commit b48f77c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,7 @@ bool X86FrameLowering::adjustStackWithPops(MachineBasicBlock &MBB,
unsigned Regs[2];
unsigned FoundRegs = 0;

auto &MRI = MBB.getParent()->getRegInfo();
auto RegMask = Prev->getOperand(1);

auto &RegClass =
Expand All @@ -2548,6 +2549,10 @@ bool X86FrameLowering::adjustStackWithPops(MachineBasicBlock &MBB,
if (!RegMask.clobbersPhysReg(Candidate))
continue;

// Don't clobber reserved registers
if (MRI.isReserved(Candidate))
continue;

bool IsDef = false;
for (const MachineOperand &MO : Prev->implicit_operands()) {
if (MO.isReg() && MO.isDef() &&
Expand Down
26 changes: 26 additions & 0 deletions test/CodeGen/X86/pop-stack-cleanup-msvc.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; RUN: llc < %s | FileCheck %s

target triple = "i686--windows-msvc"

declare { i8*, i32 } @param2_ret2(i32, i32)
declare i32 @__CxxFrameHandler3(...)


define void @test_reserved_regs() minsize optsize personality i32 (...)* @__CxxFrameHandler3 {
; CHECK-LABEL: test_reserved_regs:
; CHECK: calll _param2_ret2
; CHECK-NEXT: popl %ecx
; CHECK-NEXT: popl %edi
start:
%s = alloca i64
store i64 4, i64* %s
%0 = invoke { i8*, i32 } @param2_ret2(i32 0, i32 1)
to label %out unwind label %cleanup

out:
ret void

cleanup:
%cp = cleanuppad within none []
cleanupret from %cp unwind to caller
}

0 comments on commit b48f77c

Please sign in to comment.