blob: 68d6fd1393418c5678dc1c8b852cd2e056107dcd [file] [log] [blame]
Sanjoy Das04071082016-01-29 00:28:57 +00001; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
Philip Reames63294cb2015-04-26 19:48:03 +00002
3; constants don't get relocated.
Sanjoy Das04071082016-01-29 00:28:57 +00004@G = addrspace(1) global i8 5
5
6declare void @foo()
7
Philip Reames63294cb2015-04-26 19:48:03 +00008define i8 @test() gc "statepoint-example" {
9; CHECK-LABEL: @test
10; CHECK: gc.statepoint
11; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
Sanjoy Das04071082016-01-29 00:28:57 +000012; Mostly just here to show reasonable code test can come from.
Philip Reames63294cb2015-04-26 19:48:03 +000013entry:
Sanjoy Das04071082016-01-29 00:28:57 +000014 call void @foo() [ "deopt"() ]
Philip Reames63294cb2015-04-26 19:48:03 +000015 %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
16 ret i8 %res
17}
18
Philip Reames63294cb2015-04-26 19:48:03 +000019define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
20; CHECK-LABEL: @test2
21; CHECK: gc.statepoint
22; CHECK-NEXT: gc.relocate
23; CHECK-NEXT: icmp
Sanjoy Das04071082016-01-29 00:28:57 +000024; Globals don't move and thus don't get relocated
Philip Reames63294cb2015-04-26 19:48:03 +000025entry:
Sanjoy Das04071082016-01-29 00:28:57 +000026 call void @foo() [ "deopt"() ]
Philip Reames63294cb2015-04-26 19:48:03 +000027 %cmp = icmp eq i8 addrspace(1)* %p, null
28 br i1 %cmp, label %taken, label %not_taken
29
Sanjoy Das04071082016-01-29 00:28:57 +000030taken: ; preds = %not_taken, %entry
Philip Reames63294cb2015-04-26 19:48:03 +000031 ret i8 0
32
Sanjoy Das04071082016-01-29 00:28:57 +000033not_taken: ; preds = %entry
Philip Reames63294cb2015-04-26 19:48:03 +000034 %cmp2 = icmp ne i8 addrspace(1)* %p, null
35 br i1 %cmp2, label %taken, label %dead
36
Sanjoy Das04071082016-01-29 00:28:57 +000037dead: ; preds = %not_taken
Philip Reames63294cb2015-04-26 19:48:03 +000038 %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
Sanjoy Das04071082016-01-29 00:28:57 +000039 %res = load i8, i8 addrspace(1)* %addr
Philip Reames63294cb2015-04-26 19:48:03 +000040 ret i8 %res
41}
42
Philip Reames63294cb2015-04-26 19:48:03 +000043define i8 @test3(i1 %always_true) gc "statepoint-example" {
44; CHECK-LABEL: @test3
45; CHECK: gc.statepoint
46; CHECK-NEXT: load i8, i8 addrspace(1)* @G
47entry:
Sanjoy Das04071082016-01-29 00:28:57 +000048 call void @foo() [ "deopt"() ]
Philip Reames63294cb2015-04-26 19:48:03 +000049 %res = load i8, i8 addrspace(1)* @G, align 1
50 ret i8 %res
51}
Sanjoy Dasf3a4ee72016-01-29 16:32:25 +000052
53; Even for source languages without constant references, we can
54; see constants can show up along paths where the value is dead.
55; This is particular relevant when computing bases of PHIs.
56define i8 addrspace(1)* @test4(i8 addrspace(1)* %p) gc "statepoint-example" {
57; CHECK-LABEL: @test4
58entry:
59 %is_null = icmp eq i8 addrspace(1)* %p, null
60 br i1 %is_null, label %split, label %join
61
62split:
63 call void @foo()
64 %arg_value_addr.i = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
65 %arg_value_addr_casted.i = bitcast i8 addrspace(1)* %arg_value_addr.i to i8 addrspace(1)* addrspace(1)*
66 br label %join
67
68join:
69; CHECK-LABEL: join
70; CHECK: %addr2.base =
71 %addr2 = phi i8 addrspace(1)* addrspace(1)* [ %arg_value_addr_casted.i, %split ], [ inttoptr (i64 8 to i8 addrspace(1)* addrspace(1)*), %entry ]
72 ;; NOTE: This particular example can be jump-threaded, but in general,
73 ;; we can't, and have to deal with the resulting IR.
74 br i1 %is_null, label %early-exit, label %use
75
76early-exit:
77 ret i8 addrspace(1)* null
78
79use:
80; CHECK-LABEL: use:
81; CHECK: gc.statepoint
82; CHECK: gc.relocate
83 call void @foo()
84 %res = load i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)* %addr2, align 1
85 ret i8 addrspace(1)* %res
86}
87
88; Globals don't move and thus don't get relocated
89define i8 addrspace(1)* @test5(i1 %always_true) gc "statepoint-example" {
90; CHECK-LABEL: @test5
91; CHECK: gc.statepoint
92; CHECK-NEXT: %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
93entry:
94 call void @foo()
95 %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
96 ret i8 addrspace(1)* %res
97}
Igor Laevsky953f2d22016-05-17 13:54:10 +000098
99define i8 addrspace(1)* @test6(i64 %arg) gc "statepoint-example" {
100entry:
101 ; Don't fail any assertions and don't record null as a live value
102 ; CHECK-LABEL: test6
103 ; CHECK: gc.statepoint
104 ; CHECK-NOT: call {{.*}}gc.relocate
105 %load_addr = getelementptr i8, i8 addrspace(1)* null, i64 %arg
106 call void @foo() [ "deopt"() ]
107 ret i8 addrspace(1)* %load_addr
108}
109
110define i8 addrspace(1)* @test7(i64 %arg) gc "statepoint-example" {
111entry:
112 ; Same as test7 but use regular constant instead of a null
113 ; CHECK-LABEL: test7
114 ; CHECK: gc.statepoint
115 ; CHECK-NOT: call {{.*}}gc.relocate
116 %load_addr = getelementptr i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*), i64 %arg
117 call void @foo() [ "deopt"() ]
118 ret i8 addrspace(1)* %load_addr
119}