From c39ef776fcf7360de7ff7b7eb2e63cd3c580dd3b Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 8 Sep 2016 23:35:10 +0000 Subject: [PATCH] Win64: Don't use REX prefix for direct tail calls The REX prefix should be used on indirect jmps, but not direct ones. For direct jumps, the unwinder looks at the offset to determine if it's inside the current function. Differential Revision: https://reviews.llvm.org/D24359 llvm-svn: 281003 --- llvm/lib/Target/X86/X86ExpandPseudo.cpp | 4 +++- llvm/lib/Target/X86/X86ISelLowering.cpp | 1 - llvm/lib/Target/X86/X86InstrControl.td | 5 +---- llvm/lib/Target/X86/X86InstrInfo.cpp | 1 - llvm/lib/Target/X86/X86MCInstLower.cpp | 1 - llvm/test/CodeGen/X86/seh-catchpad.ll | 2 +- llvm/test/CodeGen/X86/tail-call-win64.ll | 2 +- llvm/test/CodeGen/X86/win64_sibcall.ll | 2 +- llvm/test/DebugInfo/COFF/register-variables.ll | 2 +- 9 files changed, 8 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/X86/X86ExpandPseudo.cpp b/llvm/lib/Target/X86/X86ExpandPseudo.cpp index 4bd01b8..701b3f2 100644 --- a/llvm/lib/Target/X86/X86ExpandPseudo.cpp +++ b/llvm/lib/Target/X86/X86ExpandPseudo.cpp @@ -121,7 +121,9 @@ bool X86ExpandPseudo::ExpandMI(MachineBasicBlock &MBB, Op = X86::TAILJMPd_CC; break; default: - Op = IsWin64 ? X86::TAILJMPd64_REX : X86::TAILJMPd64; + // Note: Win64 uses REX prefixes indirect jumps out of functions, but + // not direct ones. + Op = X86::TAILJMPd64; break; } MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op)); diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 30dbe42..6236685 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -24521,7 +24521,6 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI, case X86::TAILJMPd64: case X86::TAILJMPr64: case X86::TAILJMPm64: - case X86::TAILJMPd64_REX: case X86::TAILJMPr64_REX: case X86::TAILJMPm64_REX: llvm_unreachable("TAILJMP64 would not be touched here."); diff --git a/llvm/lib/Target/X86/X86InstrControl.td b/llvm/lib/Target/X86/X86InstrControl.td index 87f81ee..77796d2 100644 --- a/llvm/lib/Target/X86/X86InstrControl.td +++ b/llvm/lib/Target/X86/X86InstrControl.td @@ -323,11 +323,8 @@ let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst), "jmp{q}\t{*}$dst", [], IIC_JMP_MEM>; - // Win64 wants jumps leaving the function to have a REX_W prefix. + // Win64 wants indirect jumps leaving the function to have a REX_W prefix. let hasREX_WPrefix = 1 in { - def TAILJMPd64_REX : Ii32PCRel<0xE9, RawFrm, (outs), - (ins i64i32imm_pcrel:$dst), - "rex64 jmp\t$dst", [], IIC_JMP_REL>; def TAILJMPr64_REX : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst), "rex64 jmp{q}\t{*}$dst", [], IIC_JMP_MEM>; diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index d9a0897..fda3f85 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -8286,7 +8286,6 @@ bool X86InstrInfo::isTailCall(const MachineInstr &Inst) const { case X86::TAILJMPd64: case X86::TAILJMPm64: case X86::TAILJMPr64: - case X86::TAILJMPd64_REX: case X86::TAILJMPm64_REX: case X86::TAILJMPr64_REX: return true; diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp index 4619775..9ce647a 100644 --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1311,7 +1311,6 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { case X86::TAILJMPd64: case X86::TAILJMPr64_REX: case X86::TAILJMPm64_REX: - case X86::TAILJMPd64_REX: // Lower these as normal, but add some comments. OutStreamer->AddComment("TAILCALL"); break; diff --git a/llvm/test/CodeGen/X86/seh-catchpad.ll b/llvm/test/CodeGen/X86/seh-catchpad.ll index d9b4c5c..4b2a9f9 100644 --- a/llvm/test/CodeGen/X86/seh-catchpad.ll +++ b/llvm/test/CodeGen/X86/seh-catchpad.ll @@ -173,7 +173,7 @@ entry: ; CHECK: "?filt$0@0@main@@": # @"\01?filt$0@0@main@@" ; CHECK: .seh_proc "?filt$0@0@main@@" ; CHECK: .seh_endprologue -; CHECK: rex64 jmp filt # TAILCALL +; CHECK: jmp filt # TAILCALL ; CHECK: .seh_handlerdata declare i32 @filt() #1 diff --git a/llvm/test/CodeGen/X86/tail-call-win64.ll b/llvm/test/CodeGen/X86/tail-call-win64.ll index fb10d5d..6d23020 100644 --- a/llvm/test/CodeGen/X86/tail-call-win64.ll +++ b/llvm/test/CodeGen/X86/tail-call-win64.ll @@ -22,7 +22,7 @@ define void @tail_jmp_imm() { } ; CHECK-LABEL: tail_jmp_imm: -; CHECK: rex64 jmp tail_tgt +; CHECK: jmp tail_tgt @g_fptr = global void ()* @tail_tgt diff --git a/llvm/test/CodeGen/X86/win64_sibcall.ll b/llvm/test/CodeGen/X86/win64_sibcall.ll index 4001f63..4bba0e1 100644 --- a/llvm/test/CodeGen/X86/win64_sibcall.ll +++ b/llvm/test/CodeGen/X86/win64_sibcall.ll @@ -21,7 +21,7 @@ entry: ; WIN_X64: xorl %r8d, %r8d ; WIN_X64: popq %rax -; WIN_X64: rex64 jmp C2 # TAILCALL +; WIN_X64: jmp C2 # TAILCALL ; LINUX: xorl %edx, %edx ; LINUX: jmp C2 # TAILCALL diff --git a/llvm/test/DebugInfo/COFF/register-variables.ll b/llvm/test/DebugInfo/COFF/register-variables.ll index 9bb7828..5392ea6 100644 --- a/llvm/test/DebugInfo/COFF/register-variables.ll +++ b/llvm/test/DebugInfo/COFF/register-variables.ll @@ -54,7 +54,7 @@ ; ASM: addq $32, %rsp ; ASM: popq %rsi ; ASM: [[func_end:\.Ltmp.*]]: -; ASM: rex64 jmp putint # TAILCALL +; ASM: jmp putint # TAILCALL ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "p" -- 2.7.4