Skip to content

Commit b3e353d

Browse files
authored
[X86] Don't use rip-relative lea to get a function address in medium static mode (#75656)
This essentially reverts https://reviews.llvm.org/D140593. Somewhere along the line we properly fixed the medium code model to assume functions are small, so now we get a 32-bit movl as desired.
1 parent eccc1cc commit b3e353d

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18329,13 +18329,6 @@ unsigned X86TargetLowering::getGlobalWrapperKind(
1832918329
OpFlags == X86II::MO_DLLIMPORT))
1833018330
return X86ISD::WrapperRIP;
1833118331

18332-
// In the medium model, functions can always be referenced RIP-relatively,
18333-
// since they must be within 2GiB. This is also possible in non-PIC mode, and
18334-
// shorter than the 64-bit absolute immediate that would otherwise be emitted.
18335-
if (getTargetMachine().getCodeModel() == CodeModel::Medium &&
18336-
isa_and_nonnull<Function>(GV))
18337-
return X86ISD::WrapperRIP;
18338-
1833918332
// GOTPCREL references must always use RIP.
1834018333
if (OpFlags == X86II::MO_GOTPCREL || OpFlags == X86II::MO_GOTPCREL_NORELAX)
1834118334
return X86ISD::WrapperRIP;

llvm/test/CodeGen/X86/code-model-elf.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ define dso_local ptr @lea_static_fn() #0 {
829829
;
830830
; MEDIUM-STATIC-LABEL: lea_static_fn:
831831
; MEDIUM-STATIC: # %bb.0:
832-
; MEDIUM-STATIC-NEXT: leaq static_fn(%rip), %rax
832+
; MEDIUM-STATIC-NEXT: movl $static_fn, %eax
833833
; MEDIUM-STATIC-NEXT: retq
834834
;
835835
; LARGE-STATIC-LABEL: lea_static_fn:
@@ -882,7 +882,7 @@ define dso_local ptr @lea_global_fn() #0 {
882882
;
883883
; MEDIUM-STATIC-LABEL: lea_global_fn:
884884
; MEDIUM-STATIC: # %bb.0:
885-
; MEDIUM-STATIC-NEXT: leaq global_fn(%rip), %rax
885+
; MEDIUM-STATIC-NEXT: movl $global_fn, %eax
886886
; MEDIUM-STATIC-NEXT: retq
887887
;
888888
; LARGE-STATIC-LABEL: lea_global_fn:

0 commit comments

Comments
 (0)