blob: beea178b6a35421bc96bbc9eb05a5b4d7b93aa4a [file] [log] [blame]
Hans Wennborg709e0152012-11-15 11:40:00 +00001; RUN: opt < %s -globalopt -S | FileCheck %s
2
3declare void @wait()
4declare void @signal()
5declare void @start_thread(void ()*)
6
7@x = internal thread_local global [100 x i32] zeroinitializer, align 16
8@ip = internal global i32* null, align 8
9
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.
13
14define i32 @f() {
15entry:
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
18
19 ; Run g on a new thread.
20 tail call void @start_thread(void ()* @g) nounwind
21 tail call void @wait() nounwind
22
23 ; Reset x[1] for thread 1.
24 store i32 0, i32* getelementptr inbounds ([100 x i32]* @x, i64 0, i64 1), align 4
25
26 ; Read the value of @ip, which now points at x[1] for thread 2.
David Blaikiea79ac142015-02-27 21:17:42 +000027 %0 = load i32*, i32** @ip, align 8
Hans Wennborg709e0152012-11-15 11:40:00 +000028
David Blaikiea79ac142015-02-27 21:17:42 +000029 %1 = load i32, i32* %0, align 4
Hans Wennborg709e0152012-11-15 11:40:00 +000030 ret i32 %1
31
Stephen Linc1c7a132013-07-14 01:42:54 +000032; CHECK-LABEL: @f(
Hans Wennborg709e0152012-11-15 11:40:00 +000033; Make sure that the load from @ip hasn't been removed.
David Blaikiea79ac142015-02-27 21:17:42 +000034; CHECK: load i32*, i32** @ip
Hans Wennborg709e0152012-11-15 11:40:00 +000035; CHECK: ret
36}
37
38define internal void @g() nounwind uwtable {
39entry:
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
42
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
45
46 tail call void @signal() nounwind
47 ret void
48
Stephen Linc1c7a132013-07-14 01:42:54 +000049; CHECK-LABEL: @g(
Hans Wennborg709e0152012-11-15 11:40:00 +000050; Make sure that the store to @ip hasn't been removed.
51; CHECK: store {{.*}} @ip
52; CHECK: ret
53}