Skip to content

Commit 9b6b2a0

Browse files
authored
[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.
1 parent d12c892 commit 9b6b2a0

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
103103
if (isa_and_nonnull<Function>(GV))
104104
return X86II::MO_NO_FLAG; // All code is RIP-relative
105105
if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV)) {
106-
if (!TM.isLargeData(GVar))
107-
return X86II::MO_NO_FLAG;
106+
if (TM.isLargeData(GVar))
107+
return X86II::MO_GOTOFF;
108108
}
109-
return X86II::MO_GOTOFF; // Local symbols use GOTOFF.
109+
return X86II::MO_NO_FLAG; // Local symbols use GOTOFF.
110110
}
111111
llvm_unreachable("invalid code model");
112112
}

llvm/test/CodeGen/X86/code-model-elf.ll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
1111
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
1212

13-
; FIXME: small pic and medium pic w/ big enough large data threshold should be equivalent
14-
1513
; Generated from this C source:
1614
;
1715
; static int static_data[10];
@@ -577,16 +575,12 @@ define dso_local float @load_constant_pool(float %x) #0 {
577575
;
578576
; MEDIUM-SMALL-DATA-PIC-LABEL: load_constant_pool:
579577
; MEDIUM-SMALL-DATA-PIC: # %bb.0:
580-
; MEDIUM-SMALL-DATA-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
581-
; MEDIUM-SMALL-DATA-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rcx
582-
; MEDIUM-SMALL-DATA-PIC-NEXT: addss (%rax,%rcx), %xmm0
578+
; MEDIUM-SMALL-DATA-PIC-NEXT: addss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
583579
; MEDIUM-SMALL-DATA-PIC-NEXT: retq
584580
;
585581
; MEDIUM-PIC-LABEL: load_constant_pool:
586582
; MEDIUM-PIC: # %bb.0:
587-
; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
588-
; MEDIUM-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rcx
589-
; MEDIUM-PIC-NEXT: addss (%rax,%rcx), %xmm0
583+
; MEDIUM-PIC-NEXT: addss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
590584
; MEDIUM-PIC-NEXT: retq
591585
;
592586
; LARGE-PIC-LABEL: load_constant_pool:

0 commit comments

Comments
 (0)