[llvm] b3e353d - [X86] Don't use rip-relative lea to get a function address in medium static mode (#75656)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 15:15:23 PST 2023


Author: Arthur Eubanks
Date: 2023-12-15T15:15:18-08:00
New Revision: b3e353d263f9d6ef061f4e6d89619c72a3553002

URL: https://github.com/llvm/llvm-project/commit/b3e353d263f9d6ef061f4e6d89619c72a3553002
DIFF: https://github.com/llvm/llvm-project/commit/b3e353d263f9d6ef061f4e6d89619c72a3553002.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ISelLowering.cpp
    llvm/test/CodeGen/X86/code-model-elf.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index cb117475dbe4cf..99c492087a4585 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -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;

diff  --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index be93f6530ae4c4..6112f2a57b82c3 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -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:
@@ -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:


        


More information about the llvm-commits mailing list