Skip to content

Commit

Permalink
[X86] Don't use rip-relative lea to get a function address in medium …
Browse files Browse the repository at this point in the history
…static mode (llvm#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.
  • Loading branch information
aeubanks authored Dec 15, 2023
1 parent eccc1cc commit b3e353d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 0 additions & 7 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18329,13 +18329,6 @@ unsigned X86TargetLowering::getGlobalWrapperKind(
OpFlags == X86II::MO_DLLIMPORT))
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 (getTargetMachine().getCodeModel() == 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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/X86/code-model-elf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ define dso_local ptr @lea_static_fn() #0 {
;
; MEDIUM-STATIC-LABEL: lea_static_fn:
; MEDIUM-STATIC: # %bb.0:
; MEDIUM-STATIC-NEXT: leaq static_fn(%rip), %rax
; MEDIUM-STATIC-NEXT: movl $static_fn, %eax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: lea_static_fn:
Expand Down Expand Up @@ -882,7 +882,7 @@ define dso_local ptr @lea_global_fn() #0 {
;
; MEDIUM-STATIC-LABEL: lea_global_fn:
; MEDIUM-STATIC: # %bb.0:
; MEDIUM-STATIC-NEXT: leaq global_fn(%rip), %rax
; MEDIUM-STATIC-NEXT: movl $global_fn, %eax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: lea_global_fn:
Expand Down

0 comments on commit b3e353d

Please sign in to comment.