[llvm] d0a1dce - [llvm][X86] REX profile for UEFI (#138362)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 13:46:43 PDT 2025
Author: Prabhu Rajasekaran
Date: 2025-06-09T13:46:40-07:00
New Revision: d0a1dce12610c9a732bdc54b0d0863ef77999002
URL: https://github.com/llvm/llvm-project/commit/d0a1dce12610c9a732bdc54b0d0863ef77999002
DIFF: https://github.com/llvm/llvm-project/commit/d0a1dce12610c9a732bdc54b0d0863ef77999002.diff
LOG: [llvm][X86] REX profile for UEFI (#138362)
Use the appropriate REX prefix for UEFI X86_64 target.
Added:
llvm/test/CodeGen/X86/rex-profile-test.ll
Modified:
llvm/lib/Target/X86/X86ExpandPseudo.cpp
llvm/test/CodeGen/X86/musttail-varargs.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ExpandPseudo.cpp b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
index 7f06e0f3a38b2..c7abb367fad28 100644
--- a/llvm/lib/Target/X86/X86ExpandPseudo.cpp
+++ b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
@@ -301,8 +301,9 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
X86FL->emitSPUpdate(MBB, MBBI, DL, Offset, /*InEpilogue=*/true);
}
+ // Use this predicate to set REX prefix for X86_64 targets.
+ bool IsX64 = STI->isTargetWin64() || STI->isTargetUEFI64();
// Jump to label or value in register.
- bool IsWin64 = STI->isTargetWin64();
if (Opcode == X86::TCRETURNdi || Opcode == X86::TCRETURNdicc ||
Opcode == X86::TCRETURNdi64 || Opcode == X86::TCRETURNdi64cc) {
unsigned Op;
@@ -341,7 +342,7 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
} else if (Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64) {
unsigned Op = (Opcode == X86::TCRETURNmi)
? X86::TAILJMPm
- : (IsWin64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
+ : (IsX64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op));
for (unsigned i = 0; i != X86::AddrNumOperands; ++i)
MIB.add(MBBI->getOperand(i));
@@ -349,10 +350,10 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
(Opcode == X86::TCRETURNri64_ImpCall)) {
JumpTarget.setIsKill();
BuildMI(MBB, MBBI, DL,
- TII->get(IsWin64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
+ TII->get(IsX64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
.add(JumpTarget);
} else {
- assert(!IsWin64 && "Win64 requires REX for indirect jumps.");
+ assert(!IsX64 && "Win64 and UEFI64 require REX for indirect jumps.");
JumpTarget.setIsKill();
BuildMI(MBB, MBBI, DL, TII->get(X86::TAILJMPr))
.add(JumpTarget);
diff --git a/llvm/test/CodeGen/X86/musttail-varargs.ll b/llvm/test/CodeGen/X86/musttail-varargs.ll
index f9b2ce79a35ca..65cd1edd92e31 100644
--- a/llvm/test/CodeGen/X86/musttail-varargs.ll
+++ b/llvm/test/CodeGen/X86/musttail-varargs.ll
@@ -2,6 +2,7 @@
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-linux | FileCheck %s --check-prefix=LINUX
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-linux-gnux32 | FileCheck %s --check-prefix=LINUX-X32
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-windows | FileCheck %s --check-prefix=WINDOWS
+; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=x86_64-uefi | FileCheck %s --check-prefix=WINDOWS
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=i686-windows | FileCheck %s --check-prefix=X86 --check-prefix=X86-NOSSE
; RUN: llc -verify-machineinstrs < %s -enable-tail-merge=0 -mtriple=i686-windows -mattr=+sse2 | FileCheck %s --check-prefix=X86 --check-prefix=X86-SSE
diff --git a/llvm/test/CodeGen/X86/rex-profile-test.ll b/llvm/test/CodeGen/X86/rex-profile-test.ll
new file mode 100644
index 0000000000000..379d8faa4fc45
--- /dev/null
+++ b/llvm/test/CodeGen/X86/rex-profile-test.ll
@@ -0,0 +1,18 @@
+;; Test that the UEFI and Windows targets set the rex64 correctly.
+; RUN: llc -mtriple x86_64-uefi %s -o - | FileCheck %s -check-prefix=REX
+; RUN: llc -mtriple x86_64-windows-msvc %s -o - | FileCheck %s -check-prefix=REX
+; RUN: llc -mtriple x86_64-unknown-linux %s -o - | FileCheck %s -check-prefix=NOREX
+
+define void @test_tailjmp(ptr %fptr) {
+; REX-LABEL: test_tailjmp: # @test_tailjmp
+; REX: # %bb.0: # %entry
+; REX-NEXT: rex64 jmpq *%rcx # TAILCALL
+;
+; NOREX-LABEL: test_tailjmp: # @test_tailjmp
+; NOREX: .cfi_startproc
+; NOREX-NEXT: # %bb.0: # %entry
+; NOREX-NEXT: jmpq *%rdi # TAILCALL
+entry:
+ tail call void %fptr()
+ ret void
+}
More information about the llvm-commits
mailing list