[PATCH] D140593: [X86] Emit RIP-relative access to local function in PIC medium code model
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 28 11:14:54 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82be8a1d2b00: [X86] Emit RIP-relative access to local function in PIC medium code model (authored by tkoeppe, committed by MaskRay).
Changed prior to commit:
https://reviews.llvm.org/D140593?vs=485245&id=485526#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140593/new/
https://reviews.llvm.org/D140593
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/code-model-elf.ll
Index: llvm/test/CodeGen/X86/code-model-elf.ll
===================================================================
--- llvm/test/CodeGen/X86/code-model-elf.ll
+++ llvm/test/CodeGen/X86/code-model-elf.ll
@@ -270,7 +270,7 @@
;
; MEDIUM-STATIC-LABEL: lea_static_fn:
; MEDIUM-STATIC: # %bb.0:
-; MEDIUM-STATIC-NEXT: movabsq $static_fn, %rax
+; MEDIUM-STATIC-NEXT: leaq static_fn(%rip), %rax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: lea_static_fn:
@@ -285,7 +285,7 @@
;
; MEDIUM-PIC-LABEL: lea_static_fn:
; MEDIUM-PIC: # %bb.0:
-; MEDIUM-PIC-NEXT: movabsq $static_fn, %rax
+; MEDIUM-PIC-NEXT: leaq static_fn(%rip), %rax
; MEDIUM-PIC-NEXT: retq
;
; LARGE-PIC-LABEL: lea_static_fn:
@@ -308,7 +308,7 @@
;
; MEDIUM-STATIC-LABEL: lea_global_fn:
; MEDIUM-STATIC: # %bb.0:
-; MEDIUM-STATIC-NEXT: movabsq $global_fn, %rax
+; MEDIUM-STATIC-NEXT: leaq global_fn(%rip), %rax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: lea_global_fn:
@@ -323,7 +323,7 @@
;
; MEDIUM-PIC-LABEL: lea_global_fn:
; MEDIUM-PIC: # %bb.0:
-; MEDIUM-PIC-NEXT: movabsq $global_fn, %rax
+; MEDIUM-PIC-NEXT: leaq global_fn(%rip), %rax
; MEDIUM-PIC-NEXT: retq
;
; LARGE-PIC-LABEL: lea_global_fn:
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -20493,6 +20493,12 @@
(M == CodeModel::Small || M == CodeModel::Kernel))
return X86ISD::WrapperRIP;
+ // In the medium model, functions can always be referenced RIP-relatively,
+ // since they must be within 2GiB. This is also possible in non-PIC mode, and
+ // shorter than the 64-bit absolute immediate that would otherwise be emitted.
+ if (M == CodeModel::Medium && isa_and_nonnull<Function>(GV))
+ return X86ISD::WrapperRIP;
+
// GOTPCREL references must always use RIP.
if (OpFlags == X86II::MO_GOTPCREL || OpFlags == X86II::MO_GOTPCREL_NORELAX)
return X86ISD::WrapperRIP;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140593.485526.patch
Type: text/x-patch
Size: 2068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221228/8d5622df/attachment.bin>
More information about the llvm-commits
mailing list