]> granicus.if.org Git - llvm/commitdiff
[X86] Don't preserve Win64 SSE CSRs when SSE is disabled
authorReid Kleckner <rnk@google.com>
Fri, 30 Sep 2016 00:17:49 +0000 (00:17 +0000)
committerReid Kleckner <rnk@google.com>
Fri, 30 Sep 2016 00:17:49 +0000 (00:17 +0000)
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
lib/Target/X86/X86RegisterInfo.cpp
test/CodeGen/X86/win64-nosse-csrs.ll [new file with mode: 0644]

index d38145e5519f28edc805f8072f637efe14582b32..3da335af747b9690a263eb94b781dd4d6639c572 100644 (file)
@@ -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
index 3e9537bd7f55d0ce4fa905d1ac9e6309153caf7f..5a33b5defdeddd0ad6a1ba2daa542a5744f1bed4 100644 (file)
@@ -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 (file)
index 0000000..d1860b7
--- /dev/null
@@ -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 }