Skip to content

Commit fe5e5dc

Browse files
committed
[X86] Avoid clobbering ESP/RSP in the epilogue.
Summary: In r345197 ESP and RSP were added to GR32_TC/GR64_TC, allowing them to be used for tail calls, but this also caused `findDeadCallerSavedReg` to think they were acceptable targets for clobbering. Filter them out. Fixes PR40289. Patch by Geoffry Song! Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D56617 llvm-svn: 351146
1 parent 649af77 commit fe5e5dc

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB,
185185
}
186186

187187
for (auto CS : AvailableRegs)
188-
if (!Uses.count(CS) && CS != X86::RIP)
188+
if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP &&
189+
CS != X86::ESP)
189190
return CS;
190191
}
191192
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc | FileCheck %s
2+
3+
define cc 92 < 9 x i64 > @clobber() {
4+
%1 = alloca i64
5+
%2 = load volatile i64, i64* %1
6+
ret < 9 x i64 > undef
7+
; CHECK-LABEL: clobber:
8+
; CHECK-NOT: popq %rsp
9+
; CHECK: addq $8, %rsp
10+
}

llvm/test/CodeGen/X86/pr40289.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llc < %s -mtriple=i686-pc-windows-msvc | FileCheck %s
2+
3+
define < 3 x i32 > @clobber() {
4+
%1 = alloca i32
5+
%2 = load volatile i32, i32* %1
6+
ret < 3 x i32 > undef
7+
; CHECK-LABEL: clobber:
8+
; CHECK-NOT: popl %esp
9+
; CHECK: addl $4, %esp
10+
}

0 commit comments

Comments
 (0)