From 2c3be3c856183cb123b70661a6ffb3cf3a5936d5 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 30 Sep 2016 00:17:49 +0000 Subject: [PATCH] [X86] Don't preserve Win64 SSE CSRs when SSE is disabled Code that doesn't use floating point and doesn't use SSE (kernel code) shouldn't save and restore SSE registers. Fixes PR30503 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282819 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86CallingConv.td | 4 +++- lib/Target/X86/X86RegisterInfo.cpp | 7 ++++++- test/CodeGen/X86/win64-nosse-csrs.ll | 30 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/X86/win64-nosse-csrs.ll diff --git a/lib/Target/X86/X86CallingConv.td b/lib/Target/X86/X86CallingConv.td index d38145e5519..3da335af747 100644 --- a/lib/Target/X86/X86CallingConv.td +++ b/lib/Target/X86/X86CallingConv.td @@ -863,7 +863,9 @@ def CSR_64_SwiftError : CalleeSavedRegs<(sub CSR_64, R12)>; def CSR_32EHRet : CalleeSavedRegs<(add EAX, EDX, CSR_32)>; def CSR_64EHRet : CalleeSavedRegs<(add RAX, RDX, CSR_64)>; -def CSR_Win64 : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R15, +def CSR_Win64_NoSSE : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R15)>; + +def CSR_Win64 : CalleeSavedRegs<(add CSR_Win64_NoSSE, (sequence "XMM%u", 6, 15))>; // The function used by Darwin to obtain the address of a thread-local variable diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 3e9537bd7f5..5a33b5defde 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -311,6 +311,8 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { return CSR_64_MostRegs_SaveList; break; case CallingConv::X86_64_Win64: + if (!HasSSE) + return CSR_Win64_NoSSE_SaveList; return CSR_Win64_SaveList; case CallingConv::X86_64_SysV: if (CallsEHReturn) @@ -337,8 +339,11 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { } if (Is64Bit) { - if (IsWin64) + if (IsWin64) { + if (!HasSSE) + return CSR_Win64_NoSSE_SaveList; return CSR_Win64_SaveList; + } if (CallsEHReturn) return CSR_64EHRet_SaveList; if (Subtarget.getTargetLowering()->supportSwiftError() && diff --git a/test/CodeGen/X86/win64-nosse-csrs.ll b/test/CodeGen/X86/win64-nosse-csrs.ll new file mode 100644 index 00000000000..d1860b72104 --- /dev/null +++ b/test/CodeGen/X86/win64-nosse-csrs.ll @@ -0,0 +1,30 @@ +; RUN: llc < %s -mattr="-sse,-mmx,+soft-float" | FileCheck %s + +; CHECK: peach: +; CHECK: pushq %rsi +; CHECK: pushq %rdi +; CHECK-NOT: movaps +; CHECK: callq banana +; CHECK-NOT: movaps +; CHECK: popq %rdi +; CHECK: popq %rsi +; CHECK: retq + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: uwtable +define internal i64 @banana() unnamed_addr #0 { +entry-block: + ret i64 0 +} + +; Function Attrs: nounwind uwtable +define x86_64_win64cc i64 @peach() unnamed_addr #1 { +entry-block: + %0 = call i64 @banana() + ret i64 %0 +} + +attributes #0 = { uwtable } +attributes #1 = { nounwind uwtable } -- 2.50.1