Skip to content

[CodeGen] Don't treat thread local globals as large data #67764

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 1 commit into from
Sep 29, 2023

Conversation

aeubanks
Copy link
Contributor

Otherwise they may mistakenly get the large section flag.

Otherwise they may mistakenly get the large section flag.
@aeubanks aeubanks requested a review from rnk September 29, 2023 05:26
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2023

@llvm/pr-subscribers-backend-x86

Changes

Otherwise they may mistakenly get the large section flag.


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

2 Files Affected:

  • (modified) llvm/lib/Target/TargetMachine.cpp (+1-1)
  • (modified) llvm/test/CodeGen/X86/code-model-elf-sections.ll (+10)
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index a20c6847c6c590b..45fb612cb91da19 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -40,7 +40,7 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
 TargetMachine::~TargetMachine() = default;
 
 bool TargetMachine::isLargeData(const GlobalVariable *GV) const {
-  if (getTargetTriple().getArch() != Triple::x86_64)
+  if (getTargetTriple().getArch() != Triple::x86_64 || GV->isThreadLocal())
     return false;
   // Large data under the large code model still needs to be thought about, so
   // restrict this to medium.
diff --git a/llvm/test/CodeGen/X86/code-model-elf-sections.ll b/llvm/test/CodeGen/X86/code-model-elf-sections.ll
index 941c4dd1f8c9851..716bf01bb59361b 100644
--- a/llvm/test/CodeGen/X86/code-model-elf-sections.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf-sections.ll
@@ -20,21 +20,29 @@
 ; SMALL: .bss {{.*}} WA {{.*}}
 ; SMALL: .rodata {{.*}} A {{.*}}
 ; SMALL: .data.rel.ro {{.*}} WA {{.*}}
+; SMALL: .tbss {{.*}} WAT {{.*}}
+; SMALL: .tdata {{.*}} WAT {{.*}}
 
 ; SMALL-DS: .data.data {{.*}} WA {{.*}}
 ; SMALL-DS: .bss.bss {{.*}} WA {{.*}}
 ; SMALL-DS: .rodata.rodata {{.*}} A {{.*}}
 ; SMALL-DS: .data.rel.ro.relro {{.*}} WA {{.*}}
+; SMALL-DS: .tbss.tbss {{.*}} WAT {{.*}}
+; SMALL-DS: .tdata.tdata {{.*}} WAT {{.*}}
 
 ; LARGE: .ldata {{.*}} WAl {{.*}}
 ; LARGE: .lbss {{.*}} WAl {{.*}}
 ; LARGE: .lrodata {{.*}} Al {{.*}}
 ; LARGE: .ldata.rel.ro {{.*}} WAl {{.*}}
+; LARGE: .tbss {{.*}} WAT {{.*}}
+; LARGE: .tdata {{.*}} WAT {{.*}}
 
 ; LARGE-DS: .ldata.data {{.*}} WAl {{.*}}
 ; LARGE-DS: .lbss.bss {{.*}} WAl {{.*}}
 ; LARGE-DS: .lrodata.rodata {{.*}} Al {{.*}}
 ; LARGE-DS: .ldata.rel.ro.relro {{.*}} WAl {{.*}}
+; LARGE-DS: .tbss.tbss {{.*}} WAT {{.*}}
+; LARGE-DS: .tdata.tdata {{.*}} WAT {{.*}}
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64--linux"
@@ -43,5 +51,7 @@ target triple = "x86_64--linux"
 @bss = internal global [10 x i64] zeroinitializer
 @rodata = internal constant [10 x i64] zeroinitializer
 @relro = internal constant [10 x ptr] [ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func]
+@tbss = internal thread_local global [10 x i64] zeroinitializer
+@tdata = internal thread_local global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0]
 
 declare void @func()

@aeubanks
Copy link
Contributor Author

We could move the check for thread local globals into the callers and assert that we don't call isLargeData on thread local globals, but the callers are a mix of code that should only deal with non-thread local globals and code that handles all globals, so I went down the route of less code.

@aeubanks aeubanks requested a review from jyknight September 29, 2023 15:55
@aeubanks aeubanks merged commit b915f60 into llvm:main Sep 29, 2023
@aeubanks aeubanks deleted the tllarge branch September 29, 2023 19:56
tru pushed a commit that referenced this pull request Oct 2, 2023
Otherwise they may mistakenly get the large section flag.

(cherry picked from commit b915f60)
(fix was slightly different since cherry-pick didn't apply well)
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