From df7e0218205ea8dbd1275a9ac04c114ca745e372 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 15 Jan 2019 01:24:18 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351146 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86FrameLowering.cpp | 3 ++- test/CodeGen/X86/pr40289-64bit.ll | 10 ++++++++++ test/CodeGen/X86/pr40289.ll | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/X86/pr40289-64bit.ll create mode 100644 test/CodeGen/X86/pr40289.ll diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index d722c75c4f0..984db12201e 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -185,7 +185,8 @@ static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, } for (auto CS : AvailableRegs) - if (!Uses.count(CS) && CS != X86::RIP) + if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP && + CS != X86::ESP) return CS; } } diff --git a/test/CodeGen/X86/pr40289-64bit.ll b/test/CodeGen/X86/pr40289-64bit.ll new file mode 100644 index 00000000000..fd7e2d55bdc --- /dev/null +++ b/test/CodeGen/X86/pr40289-64bit.ll @@ -0,0 +1,10 @@ +; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc | FileCheck %s + +define cc 92 < 9 x i64 > @clobber() { + %1 = alloca i64 + %2 = load volatile i64, i64* %1 + ret < 9 x i64 > undef + ; CHECK-LABEL: clobber: + ; CHECK-NOT: popq %rsp + ; CHECK: addq $8, %rsp +} diff --git a/test/CodeGen/X86/pr40289.ll b/test/CodeGen/X86/pr40289.ll new file mode 100644 index 00000000000..abcb5fa41fa --- /dev/null +++ b/test/CodeGen/X86/pr40289.ll @@ -0,0 +1,10 @@ +; RUN: llc < %s -mtriple=i686-pc-windows-msvc | FileCheck %s + +define < 3 x i32 > @clobber() { + %1 = alloca i32 + %2 = load volatile i32, i32* %1 + ret < 3 x i32 > undef + ; CHECK-LABEL: clobber: + ; CHECK-NOT: popl %esp + ; CHECK: addl $4, %esp +}