Skip to content

Commit fdea82a

Browse files
committed
Revert "[X86] Handle unsized types in TargetMachine::isLargeGlobalObject() (llvm#74952)"
This reverts commit f82c85d.
1 parent c8808ba commit fdea82a

File tree

2 files changed

+36
-81
lines changed

2 files changed

+36
-81
lines changed

llvm/lib/Target/TargetMachine.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,24 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
6969
if (IsPrefix(".bss") || IsPrefix(".data") || IsPrefix(".rodata"))
7070
return false;
7171

72-
const DataLayout &DL = GV->getParent()->getDataLayout();
73-
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
74-
return Size == 0 || Size > LargeDataThreshold;
72+
// For x86-64, we treat an explicit GlobalVariable small code model to mean
73+
// that the global should be placed in a small section, and ditto for large.
74+
// Well-known section names above take precedence for correctness.
75+
if (auto CM = GV->getCodeModel()) {
76+
if (*CM == CodeModel::Small)
77+
return false;
78+
if (*CM == CodeModel::Large)
79+
return true;
80+
}
81+
82+
if (getCodeModel() == CodeModel::Medium ||
83+
getCodeModel() == CodeModel::Large) {
84+
const DataLayout &DL = GV->getParent()->getDataLayout();
85+
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
86+
return Size == 0 || Size > LargeDataThreshold;
87+
}
88+
89+
return false;
7590
}
7691

7792
bool TargetMachine::isPositionIndependent() const {

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

Lines changed: 18 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ source_filename = "model.c"
4646
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4747
target triple = "x86_64--linux"
4848

49-
%t = type opaque
50-
5149
@global_data = dso_local global [10 x i32] [i32 1, i32 2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], align 16
5250
@static_data = internal global [10 x i32] zeroinitializer, align 16
5351
@extern_data = external global [10 x i32], align 16
5452
@thread_data = external thread_local global i32, align 4
5553
@unknown_size_data = dso_local global [0 x i32] zeroinitializer, align 16
56-
@opaque = external dso_local global %t
5754
@forced_small_data = dso_local global [10 x i32] zeroinitializer, code_model "small", align 16
5855
@forced_large_data = dso_local global [10 x i32] zeroinitializer, code_model "large", align 16
5956

@@ -689,63 +686,6 @@ define dso_local i32 @load_unknown_size_data() #0 {
689686
ret i32 %rv
690687
}
691688

692-
define dso_local ptr @lea_opaque() #0 {
693-
; SMALL-STATIC-LABEL: lea_opaque:
694-
; SMALL-STATIC: # %bb.0:
695-
; SMALL-STATIC-NEXT: movl $opaque, %eax
696-
; SMALL-STATIC-NEXT: retq
697-
;
698-
; MEDIUM-STATIC-LABEL: lea_opaque:
699-
; MEDIUM-STATIC: # %bb.0:
700-
; MEDIUM-STATIC-NEXT: movabsq $opaque, %rax
701-
; MEDIUM-STATIC-NEXT: retq
702-
;
703-
; LARGE-STATIC-LABEL: lea_opaque:
704-
; LARGE-STATIC: # %bb.0:
705-
; LARGE-STATIC-NEXT: movabsq $opaque, %rax
706-
; LARGE-STATIC-NEXT: retq
707-
;
708-
; SMALL-PIC-LABEL: lea_opaque:
709-
; SMALL-PIC: # %bb.0:
710-
; SMALL-PIC-NEXT: leaq opaque(%rip), %rax
711-
; SMALL-PIC-NEXT: retq
712-
;
713-
; MEDIUM-SMALL-DATA-PIC-LABEL: lea_opaque:
714-
; MEDIUM-SMALL-DATA-PIC: # %bb.0:
715-
; MEDIUM-SMALL-DATA-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
716-
; MEDIUM-SMALL-DATA-PIC-NEXT: movabsq $opaque@GOTOFF, %rax
717-
; MEDIUM-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
718-
; MEDIUM-SMALL-DATA-PIC-NEXT: retq
719-
;
720-
; MEDIUM-PIC-LABEL: lea_opaque:
721-
; MEDIUM-PIC: # %bb.0:
722-
; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
723-
; MEDIUM-PIC-NEXT: movabsq $opaque@GOTOFF, %rax
724-
; MEDIUM-PIC-NEXT: addq %rcx, %rax
725-
; MEDIUM-PIC-NEXT: retq
726-
;
727-
; LARGE-PIC-LABEL: lea_opaque:
728-
; LARGE-PIC: # %bb.0:
729-
; LARGE-PIC-NEXT: .L11$pb:
730-
; LARGE-PIC-NEXT: leaq .L11$pb(%rip), %rax
731-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L11$pb, %rcx
732-
; LARGE-PIC-NEXT: addq %rax, %rcx
733-
; LARGE-PIC-NEXT: movabsq $opaque@GOTOFF, %rax
734-
; LARGE-PIC-NEXT: addq %rcx, %rax
735-
; LARGE-PIC-NEXT: retq
736-
;
737-
; LARGE-SMALL-DATA-PIC-LABEL: lea_opaque:
738-
; LARGE-SMALL-DATA-PIC: # %bb.0:
739-
; LARGE-SMALL-DATA-PIC-NEXT: .L11$pb:
740-
; LARGE-SMALL-DATA-PIC-NEXT: leaq .L11$pb(%rip), %rax
741-
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L11$pb, %rcx
742-
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
743-
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $opaque@GOTOFF, %rax
744-
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
745-
; LARGE-SMALL-DATA-PIC-NEXT: retq
746-
ret ptr @opaque
747-
}
748-
749689
define dso_local void @global_fn() #0 {
750690
; CHECK-LABEL: global_fn:
751691
; CHECK: # %bb.0:
@@ -807,9 +747,9 @@ define dso_local ptr @lea_static_fn() #0 {
807747
;
808748
; LARGE-PIC-LABEL: lea_static_fn:
809749
; LARGE-PIC: # %bb.0:
810-
; LARGE-PIC-NEXT: .L15$pb:
811-
; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
812-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
750+
; LARGE-PIC-NEXT: .L14$pb:
751+
; LARGE-PIC-NEXT: leaq .L14$pb(%rip), %rax
752+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
813753
; LARGE-PIC-NEXT: addq %rax, %rcx
814754
; LARGE-PIC-NEXT: movabsq $static_fn@GOTOFF, %rax
815755
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -860,9 +800,9 @@ define dso_local ptr @lea_global_fn() #0 {
860800
;
861801
; LARGE-PIC-LABEL: lea_global_fn:
862802
; LARGE-PIC: # %bb.0:
863-
; LARGE-PIC-NEXT: .L16$pb:
864-
; LARGE-PIC-NEXT: leaq .L16$pb(%rip), %rax
865-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
803+
; LARGE-PIC-NEXT: .L15$pb:
804+
; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
805+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
866806
; LARGE-PIC-NEXT: addq %rax, %rcx
867807
; LARGE-PIC-NEXT: movabsq $global_fn@GOTOFF, %rax
868808
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -913,9 +853,9 @@ define dso_local ptr @lea_extern_fn() #0 {
913853
;
914854
; LARGE-PIC-LABEL: lea_extern_fn:
915855
; LARGE-PIC: # %bb.0:
916-
; LARGE-PIC-NEXT: .L17$pb:
917-
; LARGE-PIC-NEXT: leaq .L17$pb(%rip), %rax
918-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
856+
; LARGE-PIC-NEXT: .L16$pb:
857+
; LARGE-PIC-NEXT: leaq .L16$pb(%rip), %rax
858+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
919859
; LARGE-PIC-NEXT: addq %rax, %rcx
920860
; LARGE-PIC-NEXT: movabsq $extern_fn@GOT, %rax
921861
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -966,9 +906,9 @@ define dso_local ptr @lea_ifunc() #0 {
966906
;
967907
; LARGE-PIC-LABEL: lea_ifunc:
968908
; LARGE-PIC: # %bb.0:
969-
; LARGE-PIC-NEXT: .L18$pb:
970-
; LARGE-PIC-NEXT: leaq .L18$pb(%rip), %rax
971-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
909+
; LARGE-PIC-NEXT: .L17$pb:
910+
; LARGE-PIC-NEXT: leaq .L17$pb(%rip), %rax
911+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
972912
; LARGE-PIC-NEXT: addq %rax, %rcx
973913
; LARGE-PIC-NEXT: movabsq $ifunc_func@GOT, %rax
974914
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -1019,9 +959,9 @@ define dso_local ptr @lea_dso_local_ifunc() #0 {
1019959
;
1020960
; LARGE-PIC-LABEL: lea_dso_local_ifunc:
1021961
; LARGE-PIC: # %bb.0:
1022-
; LARGE-PIC-NEXT: .L19$pb:
1023-
; LARGE-PIC-NEXT: leaq .L19$pb(%rip), %rax
1024-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L19$pb, %rcx
962+
; LARGE-PIC-NEXT: .L18$pb:
963+
; LARGE-PIC-NEXT: leaq .L18$pb(%rip), %rax
964+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
1025965
; LARGE-PIC-NEXT: addq %rax, %rcx
1026966
; LARGE-PIC-NEXT: movabsq $dso_local_ifunc_func@GOTOFF, %rax
1027967
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -1107,9 +1047,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
11071047
;
11081048
; LARGE-PIC-LABEL: load_constant_pool:
11091049
; LARGE-PIC: # %bb.0:
1110-
; LARGE-PIC-NEXT: .L21$pb:
1111-
; LARGE-PIC-NEXT: leaq .L21$pb(%rip), %rax
1112-
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L21$pb, %rcx
1050+
; LARGE-PIC-NEXT: .L20$pb:
1051+
; LARGE-PIC-NEXT: leaq .L20$pb(%rip), %rax
1052+
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L20$pb, %rcx
11131053
; LARGE-PIC-NEXT: addq %rax, %rcx
11141054
; LARGE-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
11151055
; LARGE-PIC-NEXT: addss (%rcx,%rax), %xmm0

0 commit comments

Comments
 (0)