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