Skip to content

[X86] Don't respect large data threshold for globals with an explicit section #78348

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 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions llvm/lib/Target/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
return true;
}

if (getCodeModel() == CodeModel::Medium ||
getCodeModel() == CodeModel::Large) {
// Respect large data threshold for medium and large code models.
// ... But only for globals without an explicit section. If multiple globals
// are placed in an explicit section, there's a good chance that the data
// threshold will cause the different globals to be inconsistent in whether
// they're large or small. Mixing large section flags can cause undesirable
// issues like increased relocation pressure.
if (!GV->hasSection() && (getCodeModel() == CodeModel::Medium ||
getCodeModel() == CodeModel::Large)) {
if (!GV->getValueType()->isSized())
return true;
const DataLayout &DL = GV->getParent()->getDataLayout();
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/X86/code-model-elf-sections.ll
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@

; LARGE: .data {{.*}} WA {{.*}}
; LARGE: .data.x {{.*}} WA {{.*}}
; LARGE: .data0 {{.*}} WAl {{.*}}
; LARGE: .data0 {{.*}} WA {{.*}}
; LARGE: .ldata {{.*}} WAl {{.*}}
; LARGE: .ldata.x {{.*}} WAl {{.*}}
; LARGE: .ldata0 {{.*}} WAl {{.*}}
; LARGE: .ldata0 {{.*}} WA {{.*}}
; LARGE: force_small {{.*}} WA {{.*}}
; LARGE: force_large {{.*}} WAl {{.*}}
; LARGE: foo {{.*}} WAl {{.*}}
; LARGE: foo {{.*}} WA {{.*}}
; LARGE: .bss {{.*}} WA {{.*}}
; LARGE: .lbss {{.*}} WAl {{.*}}
; LARGE: .rodata {{.*}} A {{.*}}
Expand All @@ -72,14 +72,14 @@

; LARGE-DS: .data {{.*}} WA {{.*}}
; LARGE-DS: .data.x {{.*}} WA {{.*}}
; LARGE-DS: .data0 {{.*}} WAl {{.*}}
; LARGE-DS: .data0 {{.*}} WA {{.*}}
; LARGE-DS: .ldata {{.*}} WAl {{.*}}
; LARGE-DS: .ldata.x {{.*}} WAl {{.*}}
; LARGE-DS: .ldata0 {{.*}} WAl {{.*}}
; LARGE-DS: .ldata0 {{.*}} WA {{.*}}
; LARGE-DS: .ldata.data {{.*}} WAl {{.*}}
; LARGE-DS: force_small {{.*}} WA {{.*}}
; LARGE-DS: force_large {{.*}} WAl {{.*}}
; LARGE-DS: foo {{.*}} WAl {{.*}}
; LARGE-DS: foo {{.*}} WA {{.*}}
; LARGE-DS: .bss {{.*}} WA {{.*}}
; LARGE-DS: .lbss.bss {{.*}} WAl {{.*}}
; LARGE-DS: .rodata {{.*}} A {{.*}}
Expand Down