aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/TargetMachine.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2023-12-14 09:28:27 -0800
committerArthur Eubanks <aeubanks@google.com>2023-12-14 14:12:37 -0800
commit239a41e8f2ca84b2fa5e1426e2697a2bc436d218 (patch)
tree7c5ba93d04335fb77674909040423ffcf5723413 /llvm/lib/Target/TargetMachine.cpp
parente692d0836003dead19070e5f7d199a48fa082f72 (diff)
downloadllvm-239a41e8f2ca84b2fa5e1426e2697a2bc436d218.zip
llvm-239a41e8f2ca84b2fa5e1426e2697a2bc436d218.tar.gz
llvm-239a41e8f2ca84b2fa5e1426e2697a2bc436d218.tar.bz2
Re-Reland [X86] Respect code models more when determining if a global reference can fit in 32 bits (#75386)
For non-GlobalValue references, the small and medium code models can use 32 bit constants. For GlobalValue references, use TargetMachine::isLargeGlobalObject(). Look through aliases for determining if a GlobalValue is small or large. Even the large code model can reference small objects with 32 bit constants as long as we're in no-pic mode, or if the reference is offset from the GOT. Original commit broke the build... First reland broke large PIC builds referencing small data since it was using GOTOFF as a 32-bit constant.
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r--llvm/lib/Target/TargetMachine.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 5428e14..3f96bd3 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -39,10 +39,16 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
TargetMachine::~TargetMachine() = default;
-bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
+bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
if (getTargetTriple().getArch() != Triple::x86_64)
return false;
+ auto *GO = GVal->getAliaseeObject();
+
+ // Be conservative if we can't find an underlying GlobalObject.
+ if (!GO)
+ return true;
+
auto *GV = dyn_cast<GlobalVariable>(GO);
// Functions/GlobalIFuncs are only large under the large code model.