Revert "[Analyzer][CFG] Correctly handle rebuilt default arg and default init express...
[llvm-project.git] / llvm / test / Transforms / GlobalOpt / tls.ll
blob2cc2ea4e366e34fea6f6bf017c2d2f4a96edec48
1 ; RUN: opt < %s -passes=globalopt -S | FileCheck %s
2 ; RUN: opt -emulated-tls < %s -passes=globalopt -S | FileCheck %s
4 declare void @wait()
5 declare void @signal()
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.
15 define i32 @f() {
16 entry:
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
33   ret i32 %1
35 ; CHECK-LABEL: @f(
36 ; Make sure that the load from @ip hasn't been removed.
37 ; CHECK: load ptr, ptr @ip
38 ; CHECK: ret
41 define internal void @g() nounwind uwtable {
42 entry:
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
52   ret void
54 ; CHECK-LABEL: @g(
55 ; Make sure that the store to @ip hasn't been removed.
56 ; CHECK: store {{.*}} @ip
57 ; CHECK: ret