Skip to content

Commit fd23f45

Browse files
authored
[ConstantMerge] Don't merge thread_local constants with non-thread_local constants (#105)
Fixes PR49932 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D100322
1 parent 06c2b9d commit fd23f45

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Transforms/IPO/ConstantMerge.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ isUnmergeableGlobal(GlobalVariable *GV,
9595
// Only process constants with initializers in the default address space.
9696
return !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
9797
GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
98+
// Don't touch thread-local variables.
99+
GV->isThreadLocal() ||
98100
// Don't touch values marked with attribute(used).
99101
UsedGlobals.count(GV);
100102
}

llvm/test/Transforms/ConstantMerge/dont-merge.ll

+12
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ define void @test4(i32** %P1, i32** %P2, i32** %P3, i32** %P4, i32** %P5, i32**
8080
store i32* @T4D2, i32** %P8
8181
ret void
8282
}
83+
84+
; CHECK: @T5tls
85+
; CHECK: @T5ua
86+
87+
@T5tls = private thread_local constant i32 555
88+
@T5ua = private unnamed_addr constant i32 555
89+
90+
define void @test5(i32** %P1, i32** %P2) {
91+
store i32* @T5tls, i32** %P1
92+
store i32* @T5ua, i32** %P2
93+
ret void
94+
}

0 commit comments

Comments
 (0)