[llvm] 9b6b2a0 - [X86] Use RIP-relative for non-globals in medium code model in classifyLocalReference() (#67070)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 16:50:37 PDT 2023


Author: Arthur Eubanks
Date: 2023-09-21T16:50:33-07:00
New Revision: 9b6b2a0cec53b46e5fc1f9b19dbd5911000f6a37

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

LOG: [X86] Use RIP-relative for non-globals in medium code model in classifyLocalReference() (#67070)

We only want to treat globals as potentially far away, not other things
like constants in the constant pool.
This matches the object file emission that only puts the large section
flag on globals.

Remove FIXME since the remaining differences are accesses to 0 sized
globals which are intentional.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 0daa2ab5dc942fa..085fdafa6b9f2c4 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -103,10 +103,10 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
         if (isa_and_nonnull<Function>(GV))
           return X86II::MO_NO_FLAG; // All code is RIP-relative
         if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV)) {
-          if (!TM.isLargeData(GVar))
-            return X86II::MO_NO_FLAG;
+          if (TM.isLargeData(GVar))
+            return X86II::MO_GOTOFF;
         }
-        return X86II::MO_GOTOFF;    // Local symbols use GOTOFF.
+        return X86II::MO_NO_FLAG;    // Local symbols use GOTOFF.
       }
       llvm_unreachable("invalid code model");
     }

diff  --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index 4bb6d04592b1f64..901a62d26f77e8a 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -10,8 +10,6 @@
 ; RUN: llc -verify-machineinstrs < %s -relocation-model=pic    -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
 ; RUN: llc -verify-machineinstrs < %s -relocation-model=pic    -code-model=large  | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
 
-; FIXME: small pic and medium pic w/ big enough large data threshold should be equivalent
-
 ; Generated from this C source:
 ;
 ; static int static_data[10];
@@ -577,16 +575,12 @@ define dso_local float @load_constant_pool(float %x) #0 {
 ;
 ; MEDIUM-SMALL-DATA-PIC-LABEL: load_constant_pool:
 ; MEDIUM-SMALL-DATA-PIC:       # %bb.0:
-; MEDIUM-SMALL-DATA-PIC-NEXT:    leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
-; MEDIUM-SMALL-DATA-PIC-NEXT:    movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rcx
-; MEDIUM-SMALL-DATA-PIC-NEXT:    addss (%rax,%rcx), %xmm0
+; MEDIUM-SMALL-DATA-PIC-NEXT:    addss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
 ; MEDIUM-SMALL-DATA-PIC-NEXT:    retq
 ;
 ; MEDIUM-PIC-LABEL: load_constant_pool:
 ; MEDIUM-PIC:       # %bb.0:
-; MEDIUM-PIC-NEXT:    leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
-; MEDIUM-PIC-NEXT:    movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rcx
-; MEDIUM-PIC-NEXT:    addss (%rax,%rcx), %xmm0
+; MEDIUM-PIC-NEXT:    addss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
 ; MEDIUM-PIC-NEXT:    retq
 ;
 ; LARGE-PIC-LABEL: load_constant_pool:


        


More information about the llvm-commits mailing list