From 50bbc2de6dada2e23638275a9c12a7d7c339fbec 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 --- lib/Target/X86/X86ExpandPseudo.cpp | 4 +++- lib/Target/X86/X86ISelLowering.cpp | 1 - lib/Target/X86/X86InstrControl.td | 5 +---- lib/Target/X86/X86InstrInfo.cpp | 1 - lib/Target/X86/X86MCInstLower.cpp | 1 - test/CodeGen/X86/seh-catchpad.ll | 2 +- test/CodeGen/X86/tail-call-win64.ll | 2 +- test/CodeGen/X86/win64_sibcall.ll | 2 +- test/DebugInfo/COFF/register-variables.ll | 2 +- 9 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/Target/X86/X86ExpandPseudo.cpp b/lib/Target/X86/X86ExpandPseudo.cpp index 4bd01b8f00f..701b3f29957 100644 --- a/lib/Target/X86/X86ExpandPseudo.cpp +++ b/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/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 30dbe42bec2..62366850a6f 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/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/lib/Target/X86/X86InstrControl.td b/lib/Target/X86/X86InstrControl.td index 87f81ee73ac..77796d23736 100644 --- a/lib/Target/X86/X86InstrControl.td +++ b/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/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index d9a0897c24d..fda3f85a198 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/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/lib/Target/X86/X86MCInstLower.cpp b/lib/Target/X86/X86MCInstLower.cpp index 46197756566..9ce647a8068 100644 --- a/lib/Target/X86/X86MCInstLower.cpp +++ b/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/test/CodeGen/X86/seh-catchpad.ll b/test/CodeGen/X86/seh-catchpad.ll index d9b4c5c6bcf..4b2a9f9b6d8 100644 --- a/test/CodeGen/X86/seh-catchpad.ll +++ b/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/test/CodeGen/X86/tail-call-win64.ll b/test/CodeGen/X86/tail-call-win64.ll index fb10d5d2a24..6d230201a7a 100644 --- a/test/CodeGen/X86/tail-call-win64.ll +++ b/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/test/CodeGen/X86/win64_sibcall.ll b/test/CodeGen/X86/win64_sibcall.ll index 4001f638c2a..4bba0e1e0ac 100644 --- a/test/CodeGen/X86/win64_sibcall.ll +++ b/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/test/DebugInfo/COFF/register-variables.ll b/test/DebugInfo/COFF/register-variables.ll index 9bb782853a3..5392ea6238e 100644 --- a/test/DebugInfo/COFF/register-variables.ll +++ b/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"