1 ; RUN: opt < %s -passes=globalopt -S | FileCheck %s
2 ; RUN: opt -emulated-tls < %s -passes=globalopt -S | FileCheck %s
6 declare void @start_thread(ptr)
8 @x = internal thread_local global [100 x i32] zeroinitializer, align 16
9 @ip = internal global ptr 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 %p = call ptr @llvm.threadlocal.address(ptr @x)
19 %addr = getelementptr inbounds [100 x i32], ptr %p, i64 0, i64 1
20 store ptr %addr, ptr @ip, align 8
22 ; Run g on a new thread.
23 tail call void @start_thread(ptr @g) nounwind
24 tail call void @wait() nounwind
26 ; Reset x[1] for thread 1.
27 store i32 0, ptr %addr, align 4
29 ; Read the value of @ip, which now points at x[1] for thread 2.
30 %0 = load ptr, ptr @ip, align 8
32 %1 = load i32, ptr %0, align 4
36 ; Make sure that the load from @ip hasn't been removed.
37 ; CHECK: load ptr, ptr @ip
41 define internal void @g() nounwind uwtable {
43 ; Set @ip to point to x[1] for thread 2.
44 %p = call ptr @llvm.threadlocal.address(ptr @x)
45 %addr = getelementptr inbounds [100 x i32], ptr %p, i64 0, i64 1
46 store ptr %addr, ptr @ip, align 8
48 ; Store 50 in x[1] for thread 2.
49 store i32 50, ptr %addr, align 4
51 tail call void @signal() nounwind
55 ; Make sure that the store to @ip hasn't been removed.
56 ; CHECK: store {{.*}} @ip