[PATCH] D140593: [X86] Emit RIP-relative access to local function in PIC medium code model
Thomas Köppe via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 24 16:53:29 PST 2022
tkoeppe updated this revision to Diff 485212.
tkoeppe marked an inline comment as done.
tkoeppe added a comment.
Moved new condition further down, so it appears after the more common checks. Also changed the diff header to work with `-p1`, not `-p0`.
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
@@ -20489,10 +20489,18 @@
return X86ISD::Wrapper;
CodeModel::Model M = getTargetMachine().getCodeModel();
+
if (Subtarget.isPICStyleRIPRel() &&
(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.485212.patch
Type: text/x-patch
Size: 2206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221225/94416d1f/attachment.bin>
More information about the llvm-commits
mailing list