diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp --- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp +++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp @@ -105,6 +105,8 @@ return CanMerge::No; if (hasMetadataOtherThanDebugLoc(Old)) return CanMerge::No; + if (Old->getThreadLocalMode() != New->getThreadLocalMode()) + return CanMerge::No; assert(!hasMetadataOtherThanDebugLoc(New)); if (!Old->hasGlobalUnnamedAddr()) New->setUnnamedAddr(GlobalValue::UnnamedAddr::None); diff --git a/llvm/test/Transforms/ConstantMerge/dont-merge.ll b/llvm/test/Transforms/ConstantMerge/dont-merge.ll --- a/llvm/test/Transforms/ConstantMerge/dont-merge.ll +++ b/llvm/test/Transforms/ConstantMerge/dont-merge.ll @@ -80,3 +80,15 @@ store i32* @T4D2, i32** %P8 ret void } + +; CHECK: @T5tls +; CHECK: @T5ua + +@T5tls = private thread_local constant i32 555 +@T5ua = private unnamed_addr constant i32 555 + +define void @test5(i32** %P1, i32** %P2) { + store i32* @T5tls, i32** %P1 + store i32* @T5ua, i32** %P2 + ret void +}