blob: d010b96188f19a8c21185aec06b8f95c66ec89d8 [file] [log] [blame]
Hans Wennborg709e0152012-11-15 11:40:00 +00001; RUN: opt < %s -globalopt -S | FileCheck %s
Chih-Hung Hsieh1e859582015-07-28 16:24:05 +00002; RUN: opt -emulated-tls < %s -globalopt -S | FileCheck %s
Hans Wennborg709e0152012-11-15 11:40:00 +00003
4declare void @wait()
5declare void @signal()
6declare void @start_thread(void ()*)
7
8@x = internal thread_local global [100 x i32] zeroinitializer, align 16
9@ip = internal global i32* null, align 8
10
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.
14
15define i32 @f() {
16entry:
17 ; Set @ip to point to x[1] for thread 1.
David Blaikief72d05b2015-03-13 18:20:45 +000018 store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
Hans Wennborg709e0152012-11-15 11:40:00 +000019
20 ; Run g on a new thread.
21 tail call void @start_thread(void ()* @g) nounwind
22 tail call void @wait() nounwind
23
24 ; Reset x[1] for thread 1.
David Blaikief72d05b2015-03-13 18:20:45 +000025 store i32 0, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
Hans Wennborg709e0152012-11-15 11:40:00 +000026
27 ; Read the value of @ip, which now points at x[1] for thread 2.
David Blaikiea79ac142015-02-27 21:17:42 +000028 %0 = load i32*, i32** @ip, align 8
Hans Wennborg709e0152012-11-15 11:40:00 +000029
David Blaikiea79ac142015-02-27 21:17:42 +000030 %1 = load i32, i32* %0, align 4
Hans Wennborg709e0152012-11-15 11:40:00 +000031 ret i32 %1
32
Stephen Linc1c7a132013-07-14 01:42:54 +000033; CHECK-LABEL: @f(
Hans Wennborg709e0152012-11-15 11:40:00 +000034; Make sure that the load from @ip hasn't been removed.
David Blaikiea79ac142015-02-27 21:17:42 +000035; CHECK: load i32*, i32** @ip
Hans Wennborg709e0152012-11-15 11:40:00 +000036; CHECK: ret
37}
38
39define internal void @g() nounwind uwtable {
40entry:
41 ; Set @ip to point to x[1] for thread 2.
David Blaikief72d05b2015-03-13 18:20:45 +000042 store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
Hans Wennborg709e0152012-11-15 11:40:00 +000043
44 ; Store 50 in x[1] for thread 2.
David Blaikief72d05b2015-03-13 18:20:45 +000045 store i32 50, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
Hans Wennborg709e0152012-11-15 11:40:00 +000046
47 tail call void @signal() nounwind
48 ret void
49
Stephen Linc1c7a132013-07-14 01:42:54 +000050; CHECK-LABEL: @g(
Hans Wennborg709e0152012-11-15 11:40:00 +000051; Make sure that the store to @ip hasn't been removed.
52; CHECK: store {{.*}} @ip
53; CHECK: ret
54}