[llvm] opaque (PR #74952)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 9 13:26:50 PST 2023
https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/74952
- [X86] Respect small/large globals when determining if we can use a 32-bit constant
- [X86] Handle unsized types in TargetMachine::isLargeGlobalObject()
>From 48cffce944093252738cad0856b3cfdfbe9939e3 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Fri, 8 Dec 2023 14:36:56 -0800
Subject: [PATCH 1/2] [X86] Respect small/large globals when determining if we
can use a 32-bit constant
We should look at whether or not the specific global can be addressed with 32-bit constants rather than the TU code model.
Small globals will be in the lower 32 bits of the address space for no-pic builds, except for the kernel code model.
Fixes a TODO in the test.
---
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 16 ++-
llvm/test/CodeGen/X86/code-model-elf.ll | 168 ++++++++++++++++++++++--
2 files changed, 170 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 545039b79f1616..cf014ecebe8487 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2943,12 +2943,18 @@ bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) {
if (N->getOpcode() != ISD::TargetGlobalAddress)
return TM.getCodeModel() == CodeModel::Small;
- std::optional<ConstantRange> CR =
- cast<GlobalAddressSDNode>(N)->getGlobal()->getAbsoluteSymbolRange();
- if (!CR)
- return TM.getCodeModel() == CodeModel::Small;
+ // Kernel uses upper half of address space.
+ if (TM.getCodeModel() == CodeModel::Kernel)
+ return false;
- return CR->getUnsignedMax().ult(1ull << 32);
+ const GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
+ std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange();
+ if (CR)
+ return CR->getUnsignedMax().ult(1ull << 32);
+ // We can reference small globals with 32-bit constants.
+ if (auto *GO = GV->getAliaseeObject())
+ return !TM.isLargeGlobalObject(GO);
+ return false;
}
bool X86DAGToDAGISel::selectLEA64_32Addr(SDValue N, SDValue &Base,
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll b/llvm/test/CodeGen/X86/code-model-elf.ll
index 457c6bde354f2e..eccd5c4120f964 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -9,7 +9,7 @@
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -large-data-threshold=1000 | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-SMALL-DATA-PIC
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
-; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -large-data-threshold=1000 | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
+; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -large-data-threshold=1000 | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-SMALL-DATA-PIC
; Generated from this C source:
;
@@ -86,6 +86,16 @@ define dso_local ptr @lea_static_data() #0 {
; LARGE-PIC-NEXT: movabsq $static_data at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_static_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L0$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L0$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L0$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $static_data at GOTOFF, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @static_data
}
@@ -131,6 +141,16 @@ define dso_local ptr @lea_global_data() #0 {
; LARGE-PIC-NEXT: movabsq $global_data at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_global_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L1$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L1$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L1$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $global_data at GOTOFF, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @global_data
}
@@ -174,6 +194,16 @@ define dso_local ptr @lea_extern_data() #0 {
; LARGE-PIC-NEXT: movabsq $extern_data at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_extern_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L2$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L2$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L2$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $extern_data at GOT, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @extern_data
}
@@ -221,10 +251,19 @@ define dso_local ptr @lea_unknown_size_data() #0 {
; LARGE-PIC-NEXT: movabsq $unknown_size_data at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_unknown_size_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L3$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L3$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L3$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $unknown_size_data at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @unknown_size_data
}
-; TODO: make nopic small and medium instruction sequence the same
define dso_local ptr @lea_forced_small_data() #0 {
; SMALL-STATIC-LABEL: lea_forced_small_data:
; SMALL-STATIC: # %bb.0:
@@ -233,12 +272,12 @@ define dso_local ptr @lea_forced_small_data() #0 {
;
; MEDIUM-STATIC-LABEL: lea_forced_small_data:
; MEDIUM-STATIC: # %bb.0:
-; MEDIUM-STATIC-NEXT: movabsq $forced_small_data, %rax
+; MEDIUM-STATIC-NEXT: movl $forced_small_data, %eax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: lea_forced_small_data:
; LARGE-STATIC: # %bb.0:
-; LARGE-STATIC-NEXT: movabsq $forced_small_data, %rax
+; LARGE-STATIC-NEXT: movl $forced_small_data, %eax
; LARGE-STATIC-NEXT: retq
;
; SMALL-PIC-LABEL: lea_forced_small_data:
@@ -262,9 +301,19 @@ define dso_local ptr @lea_forced_small_data() #0 {
; LARGE-PIC-NEXT: leaq .L4$pb(%rip), %rax
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L4$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
-; LARGE-PIC-NEXT: movabsq $forced_small_data at GOTOFF, %rax
+; LARGE-PIC-NEXT: movl $forced_small_data at GOTOFF, %eax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_forced_small_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L4$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L4$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L4$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $forced_small_data at GOTOFF, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @forced_small_data
}
@@ -277,13 +326,13 @@ define dso_local i32 @load_forced_small_data() #0 {
;
; MEDIUM-STATIC-LABEL: load_forced_small_data:
; MEDIUM-STATIC: # %bb.0:
-; MEDIUM-STATIC-NEXT: movabsq $forced_small_data, %rax
+; MEDIUM-STATIC-NEXT: movl $forced_small_data, %eax
; MEDIUM-STATIC-NEXT: movl 8(%rax), %eax
; MEDIUM-STATIC-NEXT: retq
;
; LARGE-STATIC-LABEL: load_forced_small_data:
; LARGE-STATIC: # %bb.0:
-; LARGE-STATIC-NEXT: movabsq $forced_small_data, %rax
+; LARGE-STATIC-NEXT: movl $forced_small_data, %eax
; LARGE-STATIC-NEXT: movl 8(%rax), %eax
; LARGE-STATIC-NEXT: retq
;
@@ -310,9 +359,19 @@ define dso_local i32 @load_forced_small_data() #0 {
; LARGE-PIC-NEXT: leaq .L5$pb(%rip), %rax
; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L5$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
-; LARGE-PIC-NEXT: movabsq $forced_small_data at GOTOFF, %rax
+; LARGE-PIC-NEXT: movl $forced_small_data at GOTOFF, %eax
; LARGE-PIC-NEXT: movl 8(%rcx,%rax), %eax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_forced_small_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L5$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L5$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L5$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $forced_small_data at GOTOFF, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: movl 8(%rcx,%rax), %eax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%rv = load i32, ptr getelementptr inbounds (i32, ptr @forced_small_data, i64 2)
ret i32 %rv
}
@@ -321,7 +380,7 @@ define dso_local i32 @load_forced_small_data() #0 {
define dso_local ptr @lea_forced_large_data() #0 {
; SMALL-STATIC-LABEL: lea_forced_large_data:
; SMALL-STATIC: # %bb.0:
-; SMALL-STATIC-NEXT: movl $forced_large_data, %eax
+; SMALL-STATIC-NEXT: movabsq $forced_large_data, %rax
; SMALL-STATIC-NEXT: retq
;
; MEDIUM-STATIC-LABEL: lea_forced_large_data:
@@ -363,6 +422,16 @@ define dso_local ptr @lea_forced_large_data() #0 {
; LARGE-PIC-NEXT: movabsq $forced_large_data at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_forced_large_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L6$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L6$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L6$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $forced_large_data at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @forced_large_data
}
@@ -413,6 +482,16 @@ define dso_local i32 @load_forced_large_data() #0 {
; LARGE-PIC-NEXT: movabsq $forced_large_data at GOTOFF, %rax
; LARGE-PIC-NEXT: movl 8(%rcx,%rax), %eax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_forced_large_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L7$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L7$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L7$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $forced_large_data at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movl 8(%rcx,%rax), %eax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%rv = load i32, ptr getelementptr inbounds (i32, ptr @forced_large_data, i64 2)
ret i32 %rv
}
@@ -462,6 +541,16 @@ define dso_local i32 @load_global_data() #0 {
; LARGE-PIC-NEXT: movabsq $global_data at GOTOFF, %rax
; LARGE-PIC-NEXT: movl 8(%rcx,%rax), %eax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_global_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L8$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L8$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L8$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $global_data at GOTOFF, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: movl 8(%rcx,%rax), %eax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%rv = load i32, ptr getelementptr inbounds ([10 x i32], ptr @global_data, i64 0, i64 2)
ret i32 %rv
}
@@ -513,6 +602,17 @@ define dso_local i32 @load_extern_data() #0 {
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
; LARGE-PIC-NEXT: movl 8(%rax), %eax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_extern_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L9$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L9$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L9$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movl $extern_data at GOT, %eax
+; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movl 8(%rax), %eax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%rv = load i32, ptr getelementptr inbounds ([10 x i32], ptr @extern_data, i64 0, i64 2)
ret i32 %rv
}
@@ -563,6 +663,16 @@ define dso_local i32 @load_unknown_size_data() #0 {
; LARGE-PIC-NEXT: movabsq $unknown_size_data at GOTOFF, %rax
; LARGE-PIC-NEXT: movl 8(%rcx,%rax), %eax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_unknown_size_data:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L10$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L10$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L10$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $unknown_size_data at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movl 8(%rcx,%rax), %eax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%rv = load i32, ptr getelementptr inbounds (i32, ptr @unknown_size_data, i64 2)
ret i32 %rv
}
@@ -623,6 +733,16 @@ define dso_local ptr @lea_static_fn() #0 {
; LARGE-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_static_fn:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L13$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L13$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L13$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @static_fn
}
@@ -666,6 +786,16 @@ define dso_local ptr @lea_global_fn() #0 {
; LARGE-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_global_fn:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L14$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L14$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @global_fn
}
@@ -709,6 +839,16 @@ define dso_local ptr @lea_extern_fn() #0 {
; LARGE-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_extern_fn:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L15$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L15$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $extern_fn at GOT, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
ret ptr @extern_fn
}
@@ -787,6 +927,16 @@ define dso_local float @load_constant_pool(float %x) #0 {
; LARGE-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-PIC-NEXT: addss (%rcx,%rax), %xmm0
; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: load_constant_pool:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L17$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L17$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addss (%rcx,%rax), %xmm0
+; LARGE-SMALL-DATA-PIC-NEXT: retq
%a = fadd float %x, 1.0
ret float %a
}
>From 11b88ac6729832076369f99bc2d6df729f034bcf Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Sat, 9 Dec 2023 13:25:34 -0800
Subject: [PATCH 2/2] [X86] Handle unsized types in
TargetMachine::isLargeGlobalObject()
isLargeGlobalObject() didn't handle opaque types, resulting in crashes.
---
llvm/lib/Target/TargetMachine.cpp | 2 +
llvm/test/CodeGen/X86/code-model-elf.ll | 108 ++++++++++++++++++------
2 files changed, 86 insertions(+), 24 deletions(-)
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index ff496d29b39121..a4e84f38431ae9 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -78,6 +78,8 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
if (getCodeModel() == CodeModel::Medium ||
getCodeModel() == CodeModel::Large) {
+ if (!GV->getValueType()->isSized())
+ return true;
const DataLayout &DL = GV->getParent()->getDataLayout();
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
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 eccd5c4120f964..ac0decc57aef83 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -36,11 +36,14 @@ source_filename = "model.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"
+%t = type opaque
+
@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
@static_data = internal global [10 x i32] zeroinitializer, align 16
@extern_data = external global [10 x i32], align 16
@thread_data = external thread_local global i32, align 4
@unknown_size_data = dso_local global [0 x i32] zeroinitializer, align 16
+ at opaque = external dso_local global %t
@forced_small_data = dso_local global [10 x i32] zeroinitializer, code_model "small", align 16
@forced_large_data = dso_local global [10 x i32] zeroinitializer, code_model "large", align 16
@@ -677,6 +680,63 @@ define dso_local i32 @load_unknown_size_data() #0 {
ret i32 %rv
}
+define dso_local ptr @lea_opaque() #0 {
+; SMALL-STATIC-LABEL: lea_opaque:
+; SMALL-STATIC: # %bb.0:
+; SMALL-STATIC-NEXT: movl $opaque, %eax
+; SMALL-STATIC-NEXT: retq
+;
+; MEDIUM-STATIC-LABEL: lea_opaque:
+; MEDIUM-STATIC: # %bb.0:
+; MEDIUM-STATIC-NEXT: movabsq $opaque, %rax
+; MEDIUM-STATIC-NEXT: retq
+;
+; LARGE-STATIC-LABEL: lea_opaque:
+; LARGE-STATIC: # %bb.0:
+; LARGE-STATIC-NEXT: movabsq $opaque, %rax
+; LARGE-STATIC-NEXT: retq
+;
+; SMALL-PIC-LABEL: lea_opaque:
+; SMALL-PIC: # %bb.0:
+; SMALL-PIC-NEXT: leaq opaque(%rip), %rax
+; SMALL-PIC-NEXT: retq
+;
+; MEDIUM-SMALL-DATA-PIC-LABEL: lea_opaque:
+; MEDIUM-SMALL-DATA-PIC: # %bb.0:
+; MEDIUM-SMALL-DATA-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
+; MEDIUM-SMALL-DATA-PIC-NEXT: movabsq $opaque at GOTOFF, %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; MEDIUM-SMALL-DATA-PIC-NEXT: retq
+;
+; MEDIUM-PIC-LABEL: lea_opaque:
+; MEDIUM-PIC: # %bb.0:
+; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
+; MEDIUM-PIC-NEXT: movabsq $opaque at GOTOFF, %rax
+; MEDIUM-PIC-NEXT: addq %rcx, %rax
+; MEDIUM-PIC-NEXT: retq
+;
+; LARGE-PIC-LABEL: lea_opaque:
+; LARGE-PIC: # %bb.0:
+; LARGE-PIC-NEXT: .L11$pb:
+; LARGE-PIC-NEXT: leaq .L11$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L11$pb, %rcx
+; LARGE-PIC-NEXT: addq %rax, %rcx
+; LARGE-PIC-NEXT: movabsq $opaque at GOTOFF, %rax
+; LARGE-PIC-NEXT: addq %rcx, %rax
+; LARGE-PIC-NEXT: retq
+;
+; LARGE-SMALL-DATA-PIC-LABEL: lea_opaque:
+; LARGE-SMALL-DATA-PIC: # %bb.0:
+; LARGE-SMALL-DATA-PIC-NEXT: .L11$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L11$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L11$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $opaque at GOTOFF, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
+; LARGE-SMALL-DATA-PIC-NEXT: retq
+ ret ptr @opaque
+}
+
define dso_local void @global_fn() #0 {
; CHECK-LABEL: global_fn:
; CHECK: # %bb.0:
@@ -726,9 +786,9 @@ define dso_local ptr @lea_static_fn() #0 {
;
; LARGE-PIC-LABEL: lea_static_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L13$pb:
-; LARGE-PIC-NEXT: leaq .L13$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L13$pb, %rcx
+; LARGE-PIC-NEXT: .L14$pb:
+; LARGE-PIC-NEXT: leaq .L14$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -736,9 +796,9 @@ define dso_local ptr @lea_static_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_static_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L13$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L13$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L13$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L14$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L14$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $static_fn at GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
@@ -779,9 +839,9 @@ define dso_local ptr @lea_global_fn() #0 {
;
; LARGE-PIC-LABEL: lea_global_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L14$pb:
-; LARGE-PIC-NEXT: leaq .L14$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
+; LARGE-PIC-NEXT: .L15$pb:
+; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-PIC-NEXT: addq %rcx, %rax
@@ -789,9 +849,9 @@ define dso_local ptr @lea_global_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_global_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L14$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L14$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L14$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L15$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L15$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $global_fn at GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addq %rcx, %rax
@@ -832,9 +892,9 @@ define dso_local ptr @lea_extern_fn() #0 {
;
; LARGE-PIC-LABEL: lea_extern_fn:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L15$pb:
-; LARGE-PIC-NEXT: leaq .L15$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
+; LARGE-PIC-NEXT: .L16$pb:
+; LARGE-PIC-NEXT: leaq .L16$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -842,9 +902,9 @@ define dso_local ptr @lea_extern_fn() #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: lea_extern_fn:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L15$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L15$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L15$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L16$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L16$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L16$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq $extern_fn at GOT, %rax
; LARGE-SMALL-DATA-PIC-NEXT: movq (%rcx,%rax), %rax
@@ -920,9 +980,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
;
; LARGE-PIC-LABEL: load_constant_pool:
; LARGE-PIC: # %bb.0:
-; LARGE-PIC-NEXT: .L17$pb:
-; LARGE-PIC-NEXT: leaq .L17$pb(%rip), %rax
-; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
+; LARGE-PIC-NEXT: .L18$pb:
+; LARGE-PIC-NEXT: leaq .L18$pb(%rip), %rax
+; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
; LARGE-PIC-NEXT: addq %rax, %rcx
; LARGE-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-PIC-NEXT: addss (%rcx,%rax), %xmm0
@@ -930,9 +990,9 @@ define dso_local float @load_constant_pool(float %x) #0 {
;
; LARGE-SMALL-DATA-PIC-LABEL: load_constant_pool:
; LARGE-SMALL-DATA-PIC: # %bb.0:
-; LARGE-SMALL-DATA-PIC-NEXT: .L17$pb:
-; LARGE-SMALL-DATA-PIC-NEXT: leaq .L17$pb(%rip), %rax
-; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L17$pb, %rcx
+; LARGE-SMALL-DATA-PIC-NEXT: .L18$pb:
+; LARGE-SMALL-DATA-PIC-NEXT: leaq .L18$pb(%rip), %rax
+; LARGE-SMALL-DATA-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L18$pb, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: addq %rax, %rcx
; LARGE-SMALL-DATA-PIC-NEXT: movabsq ${{\.?LCPI[0-9]+_[0-9]+}}@GOTOFF, %rax
; LARGE-SMALL-DATA-PIC-NEXT: addss (%rcx,%rax), %xmm0
More information about the llvm-commits
mailing list