1 ; RUN: opt < %s -globalopt -S | FileCheck %s
2 ; RUN: opt -emulated-tls < %s -globalopt -S | FileCheck %s
6 declare void @start_thread(void ()*)
8 @x = internal thread_local global [100 x i32] zeroinitializer, align 16
9 @ip = internal global i32* null, align 8
11 ; PR14309: GlobalOpt would think that the value of @ip is always the address of
12 ; x[1]. However, that address is different for different threads so @ip cannot
13 ; be replaced with a constant.
17 ; Set @ip to point to x[1] for thread 1.
18 store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
20 ; Run g on a new thread.
21 tail call void @start_thread(void ()* @g) nounwind
22 tail call void @wait() nounwind
24 ; Reset x[1] for thread 1.
25 store i32 0, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
27 ; Read the value of @ip, which now points at x[1] for thread 2.
28 %0 = load i32*, i32** @ip, align 8
30 %1 = load i32, i32* %0, align 4
34 ; Make sure that the load from @ip hasn't been removed.
35 ; CHECK: load i32*, i32** @ip
39 define internal void @g() nounwind uwtable {
41 ; Set @ip to point to x[1] for thread 2.
42 store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
44 ; Store 50 in x[1] for thread 2.
45 store i32 50, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
47 tail call void @signal() nounwind
51 ; Make sure that the store to @ip hasn't been removed.
52 ; CHECK: store {{.*}} @ip