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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 15:55:28 PDT 2023


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/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.


>From 2be755adc70e0ba1cb13239b967d1f3d2786778c Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Thu, 21 Sep 2023 15:52:31 -0700
Subject: [PATCH] [X86] Use RIP-relative for non-globals in medium code model
 in classifyLocalReference()

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.
---
 llvm/lib/Target/X86/X86Subtarget.cpp    | 6 +++---
 llvm/test/CodeGen/X86/code-model-elf.ll | 8 ++------
 2 files changed, 5 insertions(+), 9 deletions(-)

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..92c47f95ac7e1f1 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -577,16 +577,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