Skip to content

LowerTypeTests: Set small code model on imported globals. #141324

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

Conversation

pcc
Copy link
Contributor

@pcc pcc commented May 24, 2025

This is either a vtable (in .data.rel.ro) or a jump table (in .text).
Either way it's expected to be in the low 2 GiB, so set the small
code model.

pcc added 2 commits May 23, 2025 20:14
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Peter Collingbourne (pcc)

Changes

This is either a vtable (in .data.rel.ro) or a jump table (in .text).
Either way it's expected to be in the low 2 GiB, so set the small
code model.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+8-2)
  • (modified) llvm/test/Transforms/LowerTypeTests/import.ll (+7-7)
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 51667038575cc..428c4641a7f56 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1019,8 +1019,14 @@ LowerTypeTestsModule::importTypeId(StringRef TypeId) {
     return C;
   };
 
-  if (TIL.TheKind != TypeTestResolution::Unsat)
-    TIL.OffsetedGlobal = ImportGlobal("global_addr");
+  if (TIL.TheKind != TypeTestResolution::Unsat) {
+    auto *GV = ImportGlobal("global_addr");
+    // This is either a vtable (in .data.rel.ro) or a jump table (in .text).
+    // Either way it's expected to be in the low 2 GiB, so set the small code
+    // model.
+    GV->setCodeModel(CodeModel::Small);
+    TIL.OffsetedGlobal = GV;
+  }
 
   if (TIL.TheKind == TypeTestResolution::ByteArray ||
       TIL.TheKind == TypeTestResolution::Inline ||
diff --git a/llvm/test/Transforms/LowerTypeTests/import.ll b/llvm/test/Transforms/LowerTypeTests/import.ll
index 1eff4bbbbdf97..c6566b84a4361 100644
--- a/llvm/test/Transforms/LowerTypeTests/import.ll
+++ b/llvm/test/Transforms/LowerTypeTests/import.ll
@@ -6,29 +6,29 @@ target datalayout = "e-p:64:64"
 
 declare i1 @llvm.type.test(ptr %ptr, metadata %bitset) nounwind readnone
 
-; CHECK-DAG: @__typeid_single_global_addr = external hidden global [0 x i8]
-; CHECK-DAG: @__typeid_inline6_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_single_global_addr = external hidden global [0 x i8], code_model "small"
+; CHECK-DAG: @__typeid_inline6_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_inline6_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_inline6_size_m1 = external hidden global [0 x i8], !absolute_symbol !1
 ; X86-DAG: @__typeid_inline6_inline_bits = external hidden global [0 x i8], !absolute_symbol !2
-; CHECK-DAG: @__typeid_inline5_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_inline5_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_inline5_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_inline5_size_m1 = external hidden global [0 x i8], !absolute_symbol !3
 ; X86-DAG: @__typeid_inline5_inline_bits = external hidden global [0 x i8], !absolute_symbol !4
-; CHECK-DAG: @__typeid_bytearray32_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_bytearray32_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_bytearray32_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_bytearray32_size_m1 = external hidden global [0 x i8], !absolute_symbol !4
 ; CHECK-DAG: @__typeid_bytearray32_byte_array = external hidden global [0 x i8]
 ; X86-DAG: @__typeid_bytearray32_bit_mask = external hidden global [0 x i8], !absolute_symbol !0
-; CHECK-DAG: @__typeid_bytearray7_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_bytearray7_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_bytearray7_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_bytearray7_size_m1 = external hidden global [0 x i8], !absolute_symbol !5
 ; CHECK-DAG: @__typeid_bytearray7_byte_array = external hidden global [0 x i8]
 ; X86-DAG: @__typeid_bytearray7_bit_mask = external hidden global [0 x i8], !absolute_symbol !0
-; CHECK-DAG: @__typeid_allones32_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_allones32_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_allones32_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_allones32_size_m1 = external hidden global [0 x i8], !absolute_symbol !4
-; CHECK-DAG: @__typeid_allones7_global_addr = external hidden global [0 x i8]
+; CHECK-DAG: @__typeid_allones7_global_addr = external hidden global [0 x i8], code_model "small"
 ; X86-DAG: @__typeid_allones7_align = external hidden global [0 x i8], !absolute_symbol !0
 ; X86-DAG: @__typeid_allones7_size_m1 = external hidden global [0 x i8], !absolute_symbol !5
 

@pcc pcc requested a review from fmayer May 24, 2025 03:16
if (TIL.TheKind != TypeTestResolution::Unsat) {
auto *GV = ImportGlobal("global_addr");
// This is either a vtable (in .data.rel.ro) or a jump table (in .text).
// Either way it's expected to be in the low 2 GiB, so set the small code
Copy link
Contributor

Choose a reason for hiding this comment

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

preferably there would be some reference why we would expect that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment with an explanation.

pcc added 2 commits May 27, 2025 12:24
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
@pcc pcc changed the base branch from users/pcc/spr/main.lowertypetests-set-small-code-model-on-imported-globals to main May 27, 2025 19:24
@pcc pcc merged commit 782a9e9 into main May 27, 2025
7 of 14 checks passed
@pcc pcc deleted the users/pcc/spr/lowertypetests-set-small-code-model-on-imported-globals branch May 27, 2025 19:24
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 27, 2025
This is either a vtable (in .data.rel.ro) or a jump table (in .text).
Either way it's expected to be in the low 2 GiB, so set the small
code model.

Reviewers: fmayer

Reviewed By: fmayer

Pull Request: llvm/llvm-project#141324
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