[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:22:57 PST 2024


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

>From 7447205787226185ac141ceb2f55508aada03507 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    | 50 ++++++++++++++++++++++++++++
 2 files changed, 51 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..a3cdc2949ebfa0 100644
--- a/llvm/test/CodeGen/X86/call-imm.ll
+++ b/llvm/test/CodeGen/X86/call-imm.ll
@@ -1,7 +1,9 @@
+; 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
 ; RUN: llc < %s -mtriple=i386-pc-win32 -relocation-model=static | FileCheck -check-prefix X86WINSTA %s
+; RUN: llc < %s -mtriple=i386-pc-win32 -relocation-model=pic | FileCheck -check-prefix X86WINPIC %s
 
 ; Call to immediate is not safe on x86-64 unless we *know* that the
 ; call will be within 32-bits pcrel from the dest immediate.
@@ -13,6 +15,54 @@
 ; 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
+;
+; X86WINPIC-LABEL: main:
+; X86WINPIC:       # %bb.0: # %entry
+; X86WINPIC-NEXT:    movl $12345678, %eax # imm = 0xBC614E
+; X86WINPIC-NEXT:    pushl $0
+; X86WINPIC-NEXT:    calll *%eax
+; X86WINPIC-NEXT:    addl $4, %esp
+; X86WINPIC-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