Skip to content

Commit d0a1dce

Browse files
authored
[llvm][X86] REX profile for UEFI (#138362)
Use the appropriate REX prefix for UEFI X86_64 target.
1 parent d4fe522 commit d0a1dce

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

llvm/lib/Target/X86/X86ExpandPseudo.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
301301
X86FL->emitSPUpdate(MBB, MBBI, DL, Offset, /*InEpilogue=*/true);
302302
}
303303

304+
// Use this predicate to set REX prefix for X86_64 targets.
305+
bool IsX64 = STI->isTargetWin64() || STI->isTargetUEFI64();
304306
// Jump to label or value in register.
305-
bool IsWin64 = STI->isTargetWin64();
306307
if (Opcode == X86::TCRETURNdi || Opcode == X86::TCRETURNdicc ||
307308
Opcode == X86::TCRETURNdi64 || Opcode == X86::TCRETURNdi64cc) {
308309
unsigned Op;
@@ -341,18 +342,18 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
341342
} else if (Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64) {
342343
unsigned Op = (Opcode == X86::TCRETURNmi)
343344
? X86::TAILJMPm
344-
: (IsWin64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
345+
: (IsX64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
345346
MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op));
346347
for (unsigned i = 0; i != X86::AddrNumOperands; ++i)
347348
MIB.add(MBBI->getOperand(i));
348349
} else if ((Opcode == X86::TCRETURNri64) ||
349350
(Opcode == X86::TCRETURNri64_ImpCall)) {
350351
JumpTarget.setIsKill();
351352
BuildMI(MBB, MBBI, DL,
352-
TII->get(IsWin64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
353+
TII->get(IsX64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
353354
.add(JumpTarget);
354355
} else {
355-
assert(!IsWin64 && "Win64 requires REX for indirect jumps.");
356+
assert(!IsX64 && "Win64 and UEFI64 require REX for indirect jumps.");
356357
JumpTarget.setIsKill();
357358
BuildMI(MBB, MBBI, DL, TII->get(X86::TAILJMPr))
358359
.add(JumpTarget);

llvm/test/CodeGen/X86/musttail-varargs.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-linux | FileCheck %s --check-prefix=LINUX
33
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-linux-gnux32 | FileCheck %s --check-prefix=LINUX-X32
44
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-windows | FileCheck %s --check-prefix=WINDOWS
5+
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-uefi | FileCheck %s --check-prefix=WINDOWS
56
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=i686-windows | FileCheck %s --check-prefix=X86 --check-prefix=X86-NOSSE
67
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=i686-windows -mattr=+sse2 | FileCheck %s --check-prefix=X86 --check-prefix=X86-SSE
78

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;; Test that the UEFI and Windows targets set the rex64 correctly.
2+
; RUN: llc -mtriple x86_64-uefi %s -o - | FileCheck %s -check-prefix=REX
3+
; RUN: llc -mtriple x86_64-windows-msvc %s -o - | FileCheck %s -check-prefix=REX
4+
; RUN: llc -mtriple x86_64-unknown-linux %s -o - | FileCheck %s -check-prefix=NOREX
5+
6+
define void @test_tailjmp(ptr %fptr) {
7+
; REX-LABEL: test_tailjmp: # @test_tailjmp
8+
; REX: # %bb.0: # %entry
9+
; REX-NEXT: rex64 jmpq *%rcx # TAILCALL
10+
;
11+
; NOREX-LABEL: test_tailjmp: # @test_tailjmp
12+
; NOREX: .cfi_startproc
13+
; NOREX-NEXT: # %bb.0: # %entry
14+
; NOREX-NEXT: jmpq *%rdi # TAILCALL
15+
entry:
16+
tail call void %fptr()
17+
ret void
18+
}

0 commit comments

Comments
 (0)