[llvm] [X86] Resolve FIXME: WinCOFFObjectWriter::RecordRelocation can emit PC-relative calls (PR #83877)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 21:10:52 PST 2024


https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/83877

>From d6eda2a7e0095a397c433f1538899bd06bfae84a Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Mon, 4 Mar 2024 12:37:11 -0500
Subject: [PATCH] [X86] Resolve FIXME: WinCOFFObjectWriter::RecordRelocation
 can emit PC-relative calls

This has been true for a while now, but this check has not been removed.
---
 llvm/lib/Target/X86/X86Subtarget.cpp |  5 +---
 llvm/test/CodeGen/X86/call-imm.ll    | 41 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 07f535685e8f97..74d9b1bd327ea1 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -238,10 +238,7 @@ X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
 
 /// Return true if the subtarget allows calls to immediate address.
 bool X86Subtarget::isLegalToCallImmediateAddr() const {
-  // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32
-  // but WinCOFFObjectWriter::RecordRelocation cannot emit them.  Once it does,
-  // the following check for Win32 should be removed.
-  if (Is64Bit || isTargetWin32())
+  if (Is64Bit)
     return false;
   return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
 }
diff --git a/llvm/test/CodeGen/X86/call-imm.ll b/llvm/test/CodeGen/X86/call-imm.ll
index b8f5a0cb9b4287..9a661124db77fd 100644
--- a/llvm/test/CodeGen/X86/call-imm.ll
+++ b/llvm/test/CodeGen/X86/call-imm.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
 ; RUN: llc < %s -mtriple=i386-apple-darwin -relocation-model=static | FileCheck -check-prefix X86STA %s
 ; RUN: llc < %s -mtriple=i386-apple-darwin -relocation-model=pic | FileCheck -check-prefix X86PIC %s
 ; RUN: llc < %s -mtriple=i386-pc-linux -relocation-model=dynamic-no-pic | FileCheck -check-prefix X86DYN %s
@@ -13,6 +14,46 @@
 ; rdar://6904453
 
 define i32 @main() nounwind {
+; X86STA-LABEL: main:
+; X86STA:       ## %bb.0: ## %entry
+; X86STA-NEXT:    subl $12, %esp
+; X86STA-NEXT:    movl $0, (%esp)
+; X86STA-NEXT:    calll 12345678
+; X86STA-NEXT:    addl $12, %esp
+; X86STA-NEXT:    retl
+;
+; X86PIC-LABEL: main:
+; X86PIC:       ## %bb.0: ## %entry
+; X86PIC-NEXT:    subl $12, %esp
+; X86PIC-NEXT:    movl $0, (%esp)
+; X86PIC-NEXT:    movl $12345678, %eax ## imm = 0xBC614E
+; X86PIC-NEXT:    calll *%eax
+; X86PIC-NEXT:    addl $12, %esp
+; X86PIC-NEXT:    retl
+;
+; X86DYN-LABEL: main:
+; X86DYN:       # %bb.0: # %entry
+; X86DYN-NEXT:    subl $12, %esp
+; X86DYN-NEXT:    movl $0, (%esp)
+; X86DYN-NEXT:    calll 12345678
+; X86DYN-NEXT:    addl $12, %esp
+; X86DYN-NEXT:    retl
+;
+; X86WINSTA-LABEL: main:
+; X86WINSTA:       # %bb.0: # %entry
+; X86WINSTA-NEXT:    pushl $0
+; X86WINSTA-NEXT:    calll 12345678
+; X86WINSTA-NEXT:    addl $4, %esp
+; X86WINSTA-NEXT:    retl
+;
+; X64-LABEL: main:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    pushq %rax
+; X64-NEXT:    movl $12345678, %eax # imm = 0xBC614E
+; X64-NEXT:    xorl %edi, %edi
+; X64-NEXT:    callq *%rax
+; X64-NEXT:    popq %rcx
+; X64-NEXT:    retq
 entry:
 	%0 = call i32 inttoptr (i32 12345678 to ptr)(i32 0) nounwind		; <i32> [#uses=1]
 	ret i32 %0



More information about the llvm-commits mailing list