Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

aeubanks
Copy link
Contributor

@aeubanks aeubanks commented Sep 21, 2023

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.

…fyLocalReference()

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.
@aeubanks aeubanks requested a review from rnk September 21, 2023 22:55
@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2023

@llvm/pr-subscribers-backend-x86

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/67070.diff

2 Files Affected:

  • (modified) llvm/lib/Target/X86/X86Subtarget.cpp (+3-3)
  • (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+2-8)
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:

@aeubanks aeubanks merged commit 9b6b2a0 into llvm:main Sep 21, 2023
@aeubanks aeubanks deleted the medium4 branch September 21, 2023 23:50
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Sep 28, 2023
Local branch amd-gfx 8055785 Merged main:35e3939cb06d into amd-gfx:661cdc26f739
Remote branch main 9b6b2a0 [X86] Use RIP-relative for non-globals in medium code model in classifyLocalReference() (llvm#67070)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants