Skip to content

[X86] Fix determining if globals with size <8 bits are large #84975

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
Mar 12, 2024

Conversation

aeubanks
Copy link
Contributor

Previously any global under 8 bits would accidentally be considered 0 sized, which is considered a large global.

Previously any global under 8 bits would accidentally be considered 0 sized, which is considered a large global.
@aeubanks aeubanks requested a review from rnk March 12, 2024 19:20
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2024

@llvm/pr-subscribers-backend-x86

Author: Arthur Eubanks (aeubanks)

Changes

Previously any global under 8 bits would accidentally be considered 0 sized, which is considered a large global.


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

2 Files Affected:

  • (modified) llvm/lib/Target/TargetMachine.cpp (+1-1)
  • (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+1-3)
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 8b177a89c9192b..a7fe329b064ee1 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -92,7 +92,7 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
                                 GV->getName().starts_with("__stop_")))
       return true;
     const DataLayout &DL = GV->getParent()->getDataLayout();
-    uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
+    uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
     return Size == 0 || Size > LargeDataThreshold;
   }
 
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index 4e96d39d153f8c..0da62e3e7a6519 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -772,9 +772,7 @@ define dso_local i1 @load_bool() #0 {
 ;
 ; MEDIUM-SMALL-DATA-PIC-LABEL: load_bool:
 ; MEDIUM-SMALL-DATA-PIC:       # %bb.0:
-; MEDIUM-SMALL-DATA-PIC-NEXT:    leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
-; MEDIUM-SMALL-DATA-PIC-NEXT:    movabsq $bool@GOTOFF, %rcx
-; MEDIUM-SMALL-DATA-PIC-NEXT:    movzbl (%rax,%rcx), %eax
+; MEDIUM-SMALL-DATA-PIC-NEXT:    movzbl bool(%rip), %eax
 ; MEDIUM-SMALL-DATA-PIC-NEXT:    retq
 ;
 ; MEDIUM-PIC-LABEL: load_bool:

Copy link
Collaborator

@rnk rnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops :)

@aeubanks aeubanks merged commit 6bbb73b into llvm:main Mar 12, 2024
@aeubanks aeubanks deleted the large-fix branch March 12, 2024 19:43
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