Skip to content

Conversation

@Prabhuk
Copy link
Contributor

@Prabhuk Prabhuk commented May 2, 2025

Use the appropriate REX profile for UEFI X86_64 target.

Use the appropriate REX profile for UEFI X86_64 target.
@llvmbot
Copy link
Member

llvmbot commented May 2, 2025

@llvm/pr-subscribers-backend-x86

Author: Prabhu Rajasekaran (Prabhuk)

Changes

Use the appropriate REX profile for UEFI X86_64 target.


Full diff: https://github.com/llvm/llvm-project/pull/138362.diff

1 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ExpandPseudo.cpp (+6-5)
diff --git a/llvm/lib/Target/X86/X86ExpandPseudo.cpp b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
index 398b738b85697..5d1f7f7f0fe9d 100644
--- a/llvm/lib/Target/X86/X86ExpandPseudo.cpp
+++ b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
@@ -302,7 +302,7 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
     }
 
     // Jump to label or value in register.
-    bool IsWin64 = STI->isTargetWin64();
+    bool IsWinOrUEFI64 = STI->isTargetWin64() || STI->isTargetUEFI64();
     if (Opcode == X86::TCRETURNdi || Opcode == X86::TCRETURNdicc ||
         Opcode == X86::TCRETURNdi64 || Opcode == X86::TCRETURNdi64cc) {
       unsigned Op;
@@ -339,16 +339,17 @@ 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);
+      unsigned Op =
+          (Opcode == X86::TCRETURNmi)
+              ? X86::TAILJMPm
+              : (IsWinOrUEFI64 ? 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));
     } else if (Opcode == X86::TCRETURNri64) {
       JumpTarget.setIsKill();
       BuildMI(MBB, MBBI, DL,
-              TII->get(IsWin64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
+              TII->get(IsWinOrUEFI64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
           .add(JumpTarget);
     } else {
       JumpTarget.setIsKill();

@petrhosek
Copy link
Member

Would it be possible to include a test?

@Prabhuk
Copy link
Contributor Author

Prabhuk commented May 6, 2025

Added a new test for REX profile check.

Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one of the next things I'd like to see happen is if we can fix lld-link to actually link a libc and start file for UEFI using LLVM libc. Currently, we have to manually supply the paths. Ideally, this should be done automatically.

@Prabhuk Prabhuk merged commit d0a1dce into llvm:main Jun 9, 2025
7 checks passed
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Use the appropriate REX prefix for UEFI X86_64 target.
@Prabhuk Prabhuk deleted the uefi_rexprofile branch October 21, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants