summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-06-26 03:02:19 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-06-26 03:02:19 +0000
commit6098b2f5199c90ac36fda3cf6f049b72aacee27d (patch)
treef2fe726dbc3f2ffe4573887653a84539b90e2000
parent0843bff137fa43719744fba9d41fad4c827ab458 (diff)
downloadbcm5719-llvm-6098b2f5199c90ac36fda3cf6f049b72aacee27d.tar.gz
bcm5719-llvm-6098b2f5199c90ac36fda3cf6f049b72aacee27d.zip
GlobalOpt: Don't optimize thread_local for initializers
Folding a reference to a thread_local variable into another global variable's initializer is very problematic, there is no relocation that exists to represent such an access. llvm-svn: 211762
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp5
-rw-r--r--llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll12
2 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 75c1878f3fd..36c04f092bc 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1980,9 +1980,10 @@ isSimpleEnoughValueToCommit(Constant *C,
static bool isSimpleEnoughValueToCommitHelper(Constant *C,
SmallPtrSet<Constant*, 8> &SimpleConstants,
const DataLayout *DL) {
- // Simple global addresses are supported, do not allow dllimport globals.
+ // Simple global addresses are supported, do not allow dllimport or
+ // thread-local globals.
if (auto *GV = dyn_cast<GlobalValue>(C))
- return !GV->hasDLLImportStorageClass();
+ return !GV->hasDLLImportStorageClass() && !GV->isThreadLocal();
// Simple integer, undef, constant aggregate zero, etc are all supported.
if (C->getNumOperands() == 0 || isa<BlockAddress>(C))
diff --git a/llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll b/llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll
index 53e8465b5e6..8fc13304f15 100644
--- a/llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll
+++ b/llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll
@@ -72,9 +72,19 @@ entry:
ret void
}
+@threadlocalptr = global i32* null, align 4
+; CHECK: @threadlocalptr = global i32* null, align 4
+@threadlocalvar = external thread_local global i32
+define internal void @test5() {
+entry:
+ store i32* @threadlocalvar, i32** @threadlocalptr, align 4
+ ret void
+}
+
@llvm.global_ctors = appending constant
- [4 x { i32, void ()* }]
+ [5 x { i32, void ()* }]
[{ i32, void ()* } { i32 65535, void ()* @test1 },
{ i32, void ()* } { i32 65535, void ()* @test2 },
{ i32, void ()* } { i32 65535, void ()* @test3 },
+ { i32, void ()* } { i32 65535, void ()* @test4 },
{ i32, void ()* } { i32 65535, void ()* @test4 }]
OpenPOWER on IntegriCloud