]> granicus.if.org Git - llvm/commitdiff
Re-apply r282920 "X86: Allow conditional tail calls in Win64 "leaf" functions (PR26302)"
authorHans Wennborg <hans@hanshq.net>
Thu, 16 Feb 2017 19:04:42 +0000 (19:04 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 16 Feb 2017 19:04:42 +0000 (19:04 +0000)
The original commit was reverted in r283329 due to a miscompile in
Chromium. That turned out to be the same issue as PR31257, which was
fixed in r295262.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295357 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ExpandPseudo.cpp
lib/Target/X86/X86InstrInfo.cpp
test/CodeGen/X86/conditional-tailcall.ll

index c4bc29e963e7babdfbdccb60a4fe7918c74498cd..5dfd95f713015f7a1405c2ef2e7dc8a9fa6de476 100644 (file)
@@ -122,8 +122,9 @@ bool X86ExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
         Op = X86::TAILJMPd_CC;
         break;
       case X86::TCRETURNdi64cc:
-        assert(!IsWin64 && "Conditional tail calls confuse the Win64 unwinder.");
-        // TODO: We could do it for Win64 "leaf" functions though; PR30337.
+        assert(!MBB.getParent()->hasWinCFI() &&
+               "Conditional tail calls confuse "
+               "the Win64 unwinder.");
         Op = X86::TAILJMPd64_CC;
         break;
       default:
index e66ae6d34e6362f03e18b1ad56ba185e294b1e96..b259a539943b8e58ac74f6df2b456776037b0d5f 100644 (file)
@@ -5817,9 +5817,9 @@ bool X86InstrInfo::canMakeTailCallConditional(
     return false;
   }
 
-  if (Subtarget.isTargetWin64()) {
+  const MachineFunction *MF = TailCall.getParent()->getParent();
+  if (Subtarget.isTargetWin64() && MF->hasWinCFI()) {
     // Conditional tail calls confuse the Win64 unwinder.
-    // TODO: Allow them for "leaf" functions; PR30337.
     return false;
   }
 
@@ -5829,8 +5829,7 @@ bool X86InstrInfo::canMakeTailCallConditional(
     return false;
   }
 
-  const X86MachineFunctionInfo *X86FI =
-      TailCall.getParent()->getParent()->getInfo<X86MachineFunctionInfo>();
+  const X86MachineFunctionInfo *X86FI = MF->getInfo<X86MachineFunctionInfo>();
   if (X86FI->getTCReturnAddrDelta() != 0 ||
       TailCall.getOperand(1).getImm() != 0) {
     // A conditional tail call cannot do any stack adjustment.
index 379a9ad84d5994ec74aa80977b59bb2a542b69af..c00ce75b26decc5e10e553afe3c09b6c43a90e9f 100644 (file)
@@ -1,5 +1,6 @@
-; RUN: llc < %s -mtriple=i686-linux -show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK32
+; RUN: llc < %s -mtriple=i686-linux   -show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK32
 ; RUN: llc < %s -mtriple=x86_64-linux -show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK64
+; RUN: llc < %s -mtriple=x86_64-win32 -show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=WIN64
 
 declare void @foo()
 declare void @bar()
@@ -23,6 +24,28 @@ bb2:
 ; CHECK: jmp foo
 }
 
+define void @f_non_leaf(i32 %x, i32 %y) optsize {
+entry:
+  ; Force %ebx to be spilled on the stack, turning this into
+  ; not a "leaf" function for Win64.
+  tail call void asm sideeffect "", "~{ebx}"()
+
+       %p = icmp eq i32 %x, %y
+  br i1 %p, label %bb1, label %bb2
+bb1:
+  tail call void @foo()
+  ret void
+bb2:
+  tail call void @bar()
+  ret void
+
+; CHECK-LABEL: f_non_leaf:
+; WIN64-NOT: je foo
+; WIN64-NOT: jne bar
+; WIN64: jne
+; WIN64: jmp foo
+; WIN64: jmp bar
+}
 
 declare x86_thiscallcc zeroext i1 @baz(i8*, i32)
 define x86_thiscallcc zeroext i1 @BlockPlacementTest(i8* %this, i32 %x) optsize {
@@ -111,7 +134,7 @@ sw.bb22:                                          ; preds = %for.body
 
 ; Make sure Machine Copy Propagation doesn't delete the mov to %ecx becaue it
 ; thinks the conditional tail call clobbers it.
-; CHECK64-LABEL: .LBB2_11:
+; CHECK64-LABEL: .LBB3_11:
 ; CHECK64:       movzbl  (%rdi), %ecx
 ; CHECK64-NEXT:  addl    $-48, %ecx
 ; CHECK64-NEXT:  cmpl    $10, %ecx