[llvm] r239111 - [Target/X86] Don't use callee-saved registers in a Win64 tail call on non-Windows.

Charles Davis cdavis5x at gmail.com
Thu Jun 4 15:50:06 PDT 2015


Author: cdavis
Date: Thu Jun  4 17:50:05 2015
New Revision: 239111

URL: http://llvm.org/viewvc/llvm-project?rev=239111&view=rev
Log:
[Target/X86] Don't use callee-saved registers in a Win64 tail call on non-Windows.

Summary:
A small bit that I missed when I updated the X86 backend to account for
the Win64 calling convention on non-Windows. Now we don't use dead
non-volatile registers when emitting a Win64 indirect tail call on
non-Windows.

Should fix PR23710.

Test Plan: Added test for the correct behavior based on the case I posted to PR23710.

Reviewers: rnk

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10258

Modified:
    llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
    llvm/trunk/test/CodeGen/X86/sibcall-win64.ll

Modified: llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp?rev=239111&r1=239110&r2=239111&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp Thu Jun  4 17:50:05 2015
@@ -175,12 +175,12 @@ X86RegisterInfo::getPointerRegClass(cons
       return &X86::GR64_NOSPRegClass;
     return &X86::GR32_NOSPRegClass;
   case 2: // Available for tailcall (not callee-saved GPRs).
-    if (IsWin64)
+    const Function *F = MF.getFunction();
+    if (IsWin64 || (F && F->getCallingConv() == CallingConv::X86_64_Win64))
       return &X86::GR64_TCW64RegClass;
     else if (Is64Bit)
       return &X86::GR64_TCRegClass;
 
-    const Function *F = MF.getFunction();
     bool hasHipeCC = (F ? F->getCallingConv() == CallingConv::HiPE : false);
     if (hasHipeCC)
       return &X86::GR32RegClass;

Modified: llvm/trunk/test/CodeGen/X86/sibcall-win64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/sibcall-win64.ll?rev=239111&r1=239110&r2=239111&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/sibcall-win64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/sibcall-win64.ll Thu Jun  4 17:50:05 2015
@@ -1,7 +1,11 @@
 ; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s
 
 declare x86_64_win64cc void @win64_callee(i32)
+declare x86_64_win64cc void (i32)* @win64_indirect()
+declare x86_64_win64cc void @win64_other(i32)
 declare void @sysv_callee(i32)
+declare void (i32)* @sysv_indirect()
+declare void @sysv_other(i32)
 
 define void @sysv_caller(i32 %p1) {
 entry:
@@ -40,3 +44,23 @@ define x86_64_win64cc void @win64_matche
 
 ; CHECK-LABEL: win64_matched:
 ; CHECK: jmp win64_callee # TAILCALL
+
+define x86_64_win64cc void @win64_indirect_caller(i32 %p1) {
+  %1 = call x86_64_win64cc void (i32)* @win64_indirect()
+  call x86_64_win64cc void @win64_other(i32 0)
+  tail call x86_64_win64cc void %1(i32 %p1)
+  ret void
+}
+
+; CHECK-LABEL: win64_indirect_caller:
+; CHECK: jmpq *%{{rax|rcx|rdx|r8|r9|r11}} # TAILCALL
+
+define void @sysv_indirect_caller(i32 %p1) {
+  %1 = call void (i32)* @sysv_indirect()
+  call void @sysv_other(i32 0)
+  tail call void %1(i32 %p1)
+  ret void
+}
+
+; CHECK-LABEL: sysv_indirect_caller:
+; CHECK: jmpq *%{{rax|rcx|rdx|rsi|rdi|r8|r9|r11}} # TAILCALL





More information about the llvm-commits mailing list