llvm.org GIT mirror llvm / 403c3ea
[RS4GC] Clamp UseDeoptBundles to true and update tests The full diff for the test directory may be hard to read because of the filename clash; so here's all that happened as far as the tests are concerned: ``` cd test/Transforms/RewriteStatepointsForGC git rm *ll git mv deopt-bundles/* ./ rmdir deopt-bundles find . -name '*.ll' | xargs gsed -i 's/-rs4gc-use-deopt-bundles //g' ``` git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259129 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
77 changed file(s) with 1141 addition(s) and 3265 deletion(s). Raw diff Collapse all Expand all
7171 cl::location(ClobberNonLive),
7272 cl::Hidden);
7373
74 static cl::opt UseDeoptBundles("rs4gc-use-deopt-bundles", cl::Hidden,
75 cl::init(false));
74 static const bool UseDeoptBundles = true;
75
7676 static cl::opt
7777 AllowStatepointWithNoDeoptInfo("rs4gc-allow-statepoint-with-no-deopt-info",
7878 cl::Hidden, cl::init(true));
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %merged_value base %merged_value.base
33
77 entry:
88 br i1 %runtime_condition, label %here, label %there
99
10 here:
10 here: ; preds = %entry
1111 %x = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
1212 br label %merge
1313
14 there:
14 there: ; preds = %entry
1515 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
1616 br label %merge
1717
18 merge:
18 merge: ; preds = %there, %here
1919 ; CHECK-LABEL: merge:
2020 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %here ], [ %base_obj_y, %there ]
2121 %merged_value = phi i64 addrspace(1)* [ %x, %here ], [ %y, %there ]
22 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @site_for_call_safpeoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
22 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
2323 ret i64 addrspace(1)* %merged_value
2424 }
25
26 declare void @foo()
27 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
2 ; CHECK: Base Pairs (w/o Relocation):
3 ; CHECK-DAG: derived %next base %next.base
4 ; CHECK-DAG: derived %next_x base %base_obj_x
5 ; CHECK-DAG: derived %next_y base %base_obj_y
62
7 declare i1 @runtime_value()
3 declare i1 @runtime_value() "gc-leaf-function"
4
85 declare void @do_safepoint()
96
107 define void @select_of_phi(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y) gc "statepoint-example" {
118 entry:
129 br label %loop
1310
14 loop:
15 %current_x = phi i64 addrspace(1)* [ %base_obj_x , %entry ], [ %next_x, %merge ]
16 %current_y = phi i64 addrspace(1)* [ %base_obj_y , %entry ], [ %next_y, %merge ]
17 %current = phi i64 addrspace(1)* [ null , %entry ], [ %next , %merge ]
18
11 loop: ; preds = %merge, %entry
12 %current_x = phi i64 addrspace(1)* [ %base_obj_x, %entry ], [ %next_x, %merge ]
13 %current_y = phi i64 addrspace(1)* [ %base_obj_y, %entry ], [ %next_y, %merge ]
14 %current = phi i64 addrspace(1)* [ null, %entry ], [ %next, %merge ]
1915 %condition = call i1 @runtime_value()
2016 %next_x = getelementptr i64, i64 addrspace(1)* %current_x, i32 1
2117 %next_y = getelementptr i64, i64 addrspace(1)* %current_y, i32 1
22
2318 br i1 %condition, label %true, label %false
2419
25 true:
20 true: ; preds = %loop
2621 br label %merge
2722
28 false:
23 false: ; preds = %loop
2924 br label %merge
3025
31 merge:
26 merge: ; preds = %false, %true
3227 %next = phi i64 addrspace(1)* [ %next_x, %true ], [ %next_y, %false ]
33 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
28 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
3429 br label %loop
3530 }
36
37 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
31 ; CHECK: Base Pairs (w/o Relocation):
32 ; CHECK-DAG: derived %next base %next.base
33 ; CHECK-DAG: derived %next_x base %base_obj_x
34 ; CHECK-DAG: derived %next_y base %base_obj_y
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %next base %base_obj
33
1818 ; CHECK-DAG: [ %next.relocated.casted, %loop ]
1919 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
2020 %next = getelementptr i64, i64 addrspace(1)* %current, i32 1
21 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
21 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
2222 br label %loop
2323 }
24
25 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %select base @global
33
77 %derived1 = getelementptr i8, i8 addrspace(1)* @global, i64 1
88 %derived2 = getelementptr i8, i8 addrspace(1)* @global, i64 2
99 %select = select i1 %cond, i8 addrspace(1)* %derived1, i8 addrspace(1)* %derived2
10 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @extern, i32 0, i32 0, i32 0, i32 0)
10 call void @extern()
1111 ; CHECK-NOT: relocate
1212 ; CHECK: %load = load i8, i8 addrspace(1)* %select
1313 %load = load i8, i8 addrspace(1)* %select
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %derived base @global
33
55
66 define i8 @test(i64 %offset) gc "statepoint-example" {
77 %derived = getelementptr i8, i8 addrspace(1)* @global, i64 %offset
8 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @extern, i32 0, i32 0, i32 0, i32 0)
8 call void @extern()
99 ; CHECK-NOT: relocate
1010 ; CHECK-NOT: remat
1111 ; CHECK: %load = load i8, i8 addrspace(1)* %derived
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %merged_value base %base_obj
3
43
54 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj, i1 %runtime_condition) gc "statepoint-example" {
65 entry:
76 br i1 %runtime_condition, label %merge, label %there
87
9 there:
8 there: ; preds = %entry
109 %derived_obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
1110 br label %merge
1211
13 merge:
12 merge: ; preds = %there, %entry
1413 %merged_value = phi i64 addrspace(1)* [ %base_obj, %entry ], [ %derived_obj, %there ]
15 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
14 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1615 ret i64 addrspace(1)* %merged_value
1716 }
1817
1918 declare void @foo()
20 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %next.i64 base %base_obj
33
66 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
77 br label %loop
88
9 loop:
9 loop: ; preds = %loop, %entry
1010 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next.i64, %loop ]
1111 %current.i32 = bitcast i64 addrspace(1)* %current to i32 addrspace(1)*
1212 %next.i32 = getelementptr i32, i32 addrspace(1)* %current.i32, i32 1
1313 %next.i64 = bitcast i32 addrspace(1)* %next.i32 to i64 addrspace(1)*
14 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
14 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1515 br label %loop
1616 }
1717
1818 declare void @do_safepoint()
19 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
21
32 ; CHECK: derived %obj_to_consume base %obj_to_consume
43
54 declare void @foo()
5
66 declare i64 addrspace(1)* @generate_obj()
7
78 declare void @consume_obj(i64 addrspace(1)*)
89
910 define void @test(i32 %condition) gc "statepoint-example" {
1011 entry:
1112 br label %loop
1213
13 loop:
14 loop: ; preds = %merge.split, %entry
1415 ; CHECK: loop:
15 ; CHECK: %safepoint_token1 = call token (i64, i32, i64 addrspace(1)* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64f(i64 0, i32 0, i64 addrspace(1)* ()* @generate_obj, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i3
16 ; CHECK-NEXT: %obj2 = call i64 addrspace(1)* @llvm.experimental.gc.result
17 %safepoint_token1 = call token (i64, i32, i64 addrspace(1)* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64f(i64 0, i32 0, i64 addrspace(1)* ()* @generate_obj, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
18 %obj2 = call i64 addrspace(1)* @llvm.experimental.gc.result.p1i64(token %safepoint_token1)
16 ; CHECK: [[TOKEN_0:%[^ ]+]] = call token (i64, i32, i64 addrspace(1)* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* ()* @generate_obj, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i3
17 ; CHECK-NEXT: [[RESULT_0:%[^ ]+]] = call i64 addrspace(1)* @llvm.experimental.gc.result
18 %0 = call i64 addrspace(1)* @generate_obj() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1919 switch i32 %condition, label %dest_a [
2020 i32 0, label %dest_b
2121 i32 1, label %dest_c
2222 ]
2323
24 dest_a:
24 dest_a: ; preds = %loop
2525 br label %merge
2626
27 dest_b:
27 dest_b: ; preds = %loop
2828 br label %merge
2929
30 dest_c:
30 dest_c: ; preds = %loop
3131 br label %merge
3232
33 merge:
33 merge: ; preds = %dest_c, %dest_b, %dest_a
3434 ; CHECK: merge:
35 ; CHECK: %obj_to_consume = phi i64 addrspace(1)* [ %obj2, %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
36
37 %obj_to_consume = phi i64 addrspace(1)* [ %obj2, %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
38 %safepoint_token3 = call token (i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64 0, i32 0, void (i64 addrspace(1)*)* @consume_obj, i32 1, i32 0, i64 addrspace(1)* %obj_to_consume, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
35 ; CHECK: %obj_to_consume = phi i64 addrspace(1)* [ [[RESULT_0]], %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
36 %obj_to_consume = phi i64 addrspace(1)* [ %0, %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
37 call void @consume_obj(i64 addrspace(1)* %obj_to_consume) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
3938 br label %merge.split
4039
4140 merge.split: ; preds = %merge
42 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
41 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
4342 br label %loop
4443 }
45
46
47 ; Function Attrs: nounwind
48 declare i64 addrspace(1)* @llvm.experimental.gc.result.p1i64(token) #0
49 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
50 declare token @llvm.experimental.gc.statepoint.p0f_p1i64f(i64, i32, i64 addrspace(1)* ()*, i32, i32, ...)
51 declare token @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %merged_value base %merged_value.base
33
77 entry:
88 br i1 %runtime_condition, label %here, label %there
99
10 here:
10 here: ; preds = %entry
1111 br label %bump
1212
13 bump:
13 bump: ; preds = %here
1414 br label %merge
1515
16 there:
16 there: ; preds = %entry
1717 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
1818 br label %merge
1919
20 merge:
20 merge: ; preds = %there, %bump
2121 ; CHECK: merge:
2222 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %base_obj_y, %there ]
2323 ; CHECK-NEXT: %merged_value = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %y, %there ]
2424 %merged_value = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %y, %there ]
25 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
25 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
2626 ret i64 addrspace(1)* %merged_value
2727 }
28
29 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %merged_value base %merged_value.base
33
77 entry:
88 br i1 %runtime_condition_x, label %here, label %there
99
10 here:
11 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
10 here: ; preds = %entry
11 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
1212
13 bump_here_a:
13 bump_here_a: ; preds = %here
1414 %x_a = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
1515 br label %merge_here
1616
17 bump_here_b:
17 bump_here_b: ; preds = %here
1818 %x_b = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 2
1919 br label %merge_here
20
2120
22 merge_here:
23 %x = phi i64 addrspace(1)* [ %x_a , %bump_here_a ], [ %x_b , %bump_here_b ]
21 merge_here: ; preds = %bump_here_b, %bump_here_a
22 %x = phi i64 addrspace(1)* [ %x_a, %bump_here_a ], [ %x_b, %bump_here_b ]
2423 br label %merge
2524
26 there:
25 there: ; preds = %entry
2726 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
2827 br label %merge
2928
30 merge:
29 merge: ; preds = %there, %merge_here
3130 ; CHECK: merge:
3231 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %merge_here ], [ %base_obj_y, %there ]
3332 ; CHECK-NEXT: %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
3433 %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
35 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @site_for_call_safpeoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
34 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
3635 ret i64 addrspace(1)* %merged_value
3736 }
38
39 declare void @do_safepoint()
40 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %merged_value base %merged_value.base
33
44 declare void @site_for_call_safpeoint()
55
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x,
7 i64 addrspace(1)* %base_obj_y, i1 %runtime_condition_x,
8 i1 %runtime_condition_y) gc "statepoint-example" {
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition_x, i1 %runtime_condition_y) gc "statepoint-example" {
97 entry:
108 br i1 %runtime_condition_x, label %here, label %there
119
12 here:
13 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
10 here: ; preds = %entry
11 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
1412
15 bump_here_a:
13 bump_here_a: ; preds = %here
1614 %x_a = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
1715 br label %merge_here
1816
19 bump_here_b:
17 bump_here_b: ; preds = %here
2018 %x_b = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 2
2119 br label %merge_here
22
2320
24 merge_here:
21 merge_here: ; preds = %bump_here_b, %bump_here_a
2522 ; CHECK: merge_here:
2623 ; CHECK-DAG: %x.base
2724 ; CHECK-DAG: phi i64 addrspace(1)*
2825 ; CHECK-DAG: [ %base_obj_x, %bump_here_a ]
2926 ; CHECK-DAG: [ %base_obj_y, %bump_here_b ]
30 %x = phi i64 addrspace(1)* [ %x_a , %bump_here_a ], [ %x_b , %bump_here_b ]
27 %x = phi i64 addrspace(1)* [ %x_a, %bump_here_a ], [ %x_b, %bump_here_b ]
3128 br label %merge
3229
33 there:
30 there: ; preds = %entry
3431 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
3532 br label %merge
3633
37 merge:
34 merge: ; preds = %there, %merge_here
3835 ; CHECK: merge:
3936 ; CHECK-DAG: %merged_value.base
4037 ; CHECK-DAG: phi i64 addrspace(1)*
4239 ; CHECK-DAG: [ %base_obj_y, %there ]
4340 ; CHECK: %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
4441 %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
45
46 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @site_for_call_safpeoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
42 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
4743 ret i64 addrspace(1)* %merged_value
4844 }
49
50 declare void @do_safepoint()
51 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %next_element_ptr base %array_obj
33
99 %array_elems = bitcast i32 addrspace(1)* %array_len_pointer.i32 to i64 addrspace(1)* addrspace(1)*
1010 br label %loop_check
1111
12 loop_check:
12 loop_check: ; preds = %loop_back, %entry
1313 %index = phi i32 [ 0, %entry ], [ %next_index, %loop_back ]
1414 %current_element_ptr = phi i64 addrspace(1)* addrspace(1)* [ %array_elems, %entry ], [ %next_element_ptr, %loop_back ]
1515 %index_lt = icmp ult i32 %index, %array_len
1616 br i1 %index_lt, label %check_for_null, label %not_found
1717
18 check_for_null:
18 check_for_null: ; preds = %loop_check
1919 %current_element = load i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr
2020 %is_null = icmp eq i64 addrspace(1)* %current_element, null
2121 br i1 %is_null, label %found, label %loop_back
2222
23 loop_back:
23 loop_back: ; preds = %check_for_null
2424 %next_element_ptr = getelementptr i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr, i32 1
2525 %next_index = add i32 %index, 1
26 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
26 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
2727 br label %loop_check
2828
29 not_found:
29 not_found: ; preds = %loop_check
3030 ret i32 -1
3131
32 found:
32 found: ; preds = %check_for_null
3333 ret i32 %index
3434 }
3535
3636 declare void @do_safepoint()
37 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
11
22 ; CHECK: derived %next base %base_obj
33
4 declare i1 @runtime_value()
4 declare i1 @runtime_value() "gc-leaf-function"
55
66 define void @maybe_GEP(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
77 entry:
88 br label %loop
99
10 loop:
10 loop: ; preds = %loop, %entry
1111 %current = phi i64 addrspace(1)* [ %base_obj, %entry ], [ %next, %loop ]
1212 %condition = call i1 @runtime_value()
1313 %maybe_next = getelementptr i64, i64 addrspace(1)* %current, i32 1
1414 %next = select i1 %condition, i64 addrspace(1)* %maybe_next, i64 addrspace(1)* %current
15 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
15 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1616 br label %loop
1717 }
1818
1919 declare void @do_safepoint()
20 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
1
2 declare i64 addrspace(1)* @generate_obj()
3 declare void @use_obj(i64 addrspace(1)*)
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
41
52 ; The rewriting needs to make %obj loop variant by inserting a phi
63 ; of the original value and it's relocation.
4
5 declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
6
7 declare void @use_obj(i64 addrspace(1)*) "gc-leaf-function"
8
79 define void @def_use_safepoint() gc "statepoint-example" {
810 ; CHECK-LABEL: def_use_safepoint
11 ; CHECK: phi i64 addrspace(1)*
12 ; CHECK-DAG: [ %obj.relocated.casted, %loop ]
13 ; CHECK-DAG: [ %obj, %entry ]
914 entry:
1015 %obj = call i64 addrspace(1)* @generate_obj()
1116 br label %loop
1217
13 loop:
14 ; CHECK: phi i64 addrspace(1)*
15 ; CHECK-DAG: [ %obj.relocated.casted, %loop ]
16 ; CHECK-DAG: [ %obj, %entry ]
18 loop: ; preds = %loop, %entry
1719 call void @use_obj(i64 addrspace(1)* %obj)
18 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
20 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1921 br label %loop
2022 }
2123
2527
2628 define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
2729 ; CHECK-LABEL: test1
28 entry:
30 entry:
2931 br i1 undef, label %left, label %right
3032
31 left:
32 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
33 left: ; preds = %entry
3334 ; CHECK: left:
3435 ; CHECK-NEXT: %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
3536 ; CHECK-NEXT: [[CAST_L:%.*]] = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
36
3737 ; Our safepoint placement pass calls removeUnreachableBlocks, which does a bunch
3838 ; of simplifications to branch instructions. This bug is visible only when
3939 ; there are multiple branches into the same block from the same predecessor, and
4040 ; the following ceremony is to make that artefact survive a call to
4141 ; removeUnreachableBlocks. As an example, "br i1 undef, label %merge, label %merge"
4242 ; will get simplified to "br label %merge" by removeUnreachableBlocks.
43 switch i32 %unknown, label %right [ i32 0, label %merge
44 i32 1, label %merge
45 i32 5, label %merge
46 i32 3, label %right ]
43 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
44 switch i32 %unknown, label %right [
45 i32 0, label %merge
46 i32 1, label %merge
47 i32 5, label %merge
48 i32 3, label %right
49 ]
4750
48 right:
49 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
50 br label %merge
51 right: ; preds = %left, %left, %entry
5152 ; CHECK: right:
5253 ; CHECK-NEXT: %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
5354 ; CHECK-NEXT: [[CAST_R:%.*]] = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
55 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
56 br label %merge
5457
55 merge:
58 merge: ; preds = %right, %left, %left, %left
5659 ; CHECK: merge:
5760 ; CHECK-NEXT: %value.base = phi i64 addrspace(1)* [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_R]], %right ], !is_base_value !0
58 %value = phi i64 addrspace(1)* [ %a.cast, %left], [ %a.cast, %left], [ %a.cast, %left], [ %b.cast, %right]
59 %safepoint_token = call token (i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64 0, i32 0, void (i64 addrspace(1)*)* @parse_point, i32 1, i32 0, i64 addrspace(1)* %value, i32 0, i32 5, i32 0, i32 0, i32 0, i32 0, i32 0)
60
61 %value = phi i64 addrspace(1)* [ %a.cast, %left ], [ %a.cast, %left ], [ %a.cast, %left ], [ %b.cast, %right ]
62 call void @parse_point(i64 addrspace(1)* %value) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0) ]
6163 ret i64 addrspace(1)* %value
6264 }
6365
6567 ;; base defining value with inherent conflicts, we end up with a *single*
6668 ;; base phi/select per such node. This is testing an optimization, not a
6769 ;; fundemental correctness criteria
68 define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
70 define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
6971 ; CHECK-LABEL: @test2
7072 entry:
7173 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
7274 br label %loop
73
74 loop: ; preds = %loop, %entry
7575 ; CHECK-LABEL: loop
7676 ; CHECK: %current.base = phi i64 addrspace(1)*
7777 ; CHECK-DAG: [ %base_obj, %entry ]
78
7879 ; Given the two selects are equivelent, so are their base phis - ideally,
7980 ; we'd have commoned these, but that's a missed optimization, not correctness.
8081 ; CHECK-DAG: [ [[DISCARD:%.*.base.relocated.casted]], %loop ]
8485 ; CHECK: extra2 = select
8586 ; CHECK: statepoint
8687 ;; Both 'next' and 'extra2' are live across the backedge safepoint...
88
89 loop: ; preds = %loop, %entry
8790 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
8891 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
8992 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
9093 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
9194 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
92 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
95 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
9396 br label %loop
9497 }
9598
96 define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj,
97 i64 addrspace(1)* %obj2)
98 gc "statepoint-example" {
99 define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
99100 ; CHECK-LABEL: @test3
100101 entry:
101102 br i1 %cnd, label %merge, label %taken
102 taken:
103
104 taken: ; preds = %entry
103105 br label %merge
104 merge:
106
107 merge: ; preds = %taken, %entry
105108 ; CHECK-LABEL: merge:
106109 ; CHECK-NEXT: %bdv = phi
107110 ; CHECK-NEXT: gc.statepoint
108111 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %taken ]
109 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
112 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
110113 ret i64 addrspace(1)* %bdv
111114 }
112115
113 define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj,
114 i64 addrspace(1)* %obj2)
115 gc "statepoint-example" {
116 define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
116117 ; CHECK-LABEL: @test4
117118 entry:
118119 br i1 %cnd, label %merge, label %taken
119 taken:
120
121 taken: ; preds = %entry
120122 br label %merge
121 merge:
123
124 merge: ; preds = %taken, %entry
122125 ; CHECK-LABEL: merge:
123126 ; CHECK-NEXT: %bdv = phi
124127 ; CHECK-NEXT: gc.statepoint
125128 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj, %taken ]
126 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
129 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
127130 ret i64 addrspace(1)* %bdv
128131 }
129132
130 define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj,
131 i64 addrspace(1)* %obj2)
132 gc "statepoint-example" {
133 define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
133134 ; CHECK-LABEL: @test5
134135 entry:
135136 br label %merge
136 merge:
137
138 merge: ; preds = %merge, %entry
137139 ; CHECK-LABEL: merge:
138140 ; CHECK-NEXT: %bdv = phi
139141 ; CHECK-NEXT: br i1
140142 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
141143 br i1 %cnd, label %merge, label %next
142 next:
143 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
144
145 next: ; preds = %merge
146 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
144147 ret i64 addrspace(1)* %bdv
145148 }
146149
147
148150 declare void @foo()
149 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
150 declare token @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...)
None ; RUN: opt %s -rewrite-statepoints-for-gc -S | FileCheck %s
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -S | FileCheck %s
1
12
23 define i64 addrspace(1)* @test(<2 x i64 addrspace(1)*> %vec, i32 %idx) gc "statepoint-example" {
34 ; CHECK-LABEL: @test
1213 ; be to reuse the existing obj as a base since it is actually a base pointer.
1314 entry:
1415 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx
15 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
16
16 call void @do_safepoint() [ "deopt"() ]
1717 ret i64 addrspace(1)* %obj
1818 }
1919
20 define i64 addrspace(1)* @test2(<2 x i64 addrspace(1)*>* %ptr, i1 %cnd, i32 %idx1, i32 %idx2)
21 gc "statepoint-example" {
20 define i64 addrspace(1)* @test2(<2 x i64 addrspace(1)*>* %ptr, i1 %cnd, i32 %idx1, i32 %idx2) gc "statepoint-example" {
2221 ; CHECK-LABEL: test2
2322 entry:
2423 br i1 %cnd, label %taken, label %untaken
25 taken:
24
25 taken: ; preds = %entry
2626 %obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
2727 br label %merge
28 untaken:
28
29 untaken: ; preds = %entry
2930 %objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
3031 br label %merge
31 merge:
32 %vec = phi <2 x i64 addrspace(1)*> [%obja, %taken], [%objb, %untaken]
32
33 merge: ; preds = %untaken, %taken
34 %vec = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ]
3335 br i1 %cnd, label %taken2, label %untaken2
34 taken2:
36
37 taken2: ; preds = %merge
3538 %obj0 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx1
3639 br label %merge2
37 untaken2:
40
41 untaken2: ; preds = %merge
3842 %obj1 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx2
3943 br label %merge2
40 merge2:
44
45 merge2: ; preds = %untaken2, %taken2
4146 ; CHECK-LABEL: merge2:
4247 ; CHECK-NEXT: %obj = phi i64 addrspace(1)*
4348 ; CHECK-NEXT: statepoint
4449 ; CHECK: gc.relocate
4550 ; CHECK-DAG: ; (%obj, %obj)
46 %obj = phi i64 addrspace(1)* [%obj0, %taken2], [%obj1, %untaken2]
47 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
51 %obj = phi i64 addrspace(1)* [ %obj0, %taken2 ], [ %obj1, %untaken2 ]
52 call void @do_safepoint() [ "deopt"() ]
4853 ret i64 addrspace(1)* %obj
4954 }
5055
51 define i64 addrspace(1)* @test3(i64 addrspace(1)* %ptr)
52 gc "statepoint-example" {
56 define i64 addrspace(1)* @test3(i64 addrspace(1)* %ptr) gc "statepoint-example" {
5357 ; CHECK-LABEL: test3
54 entry:
55 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %ptr, i32 0
56 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
5758 ; CHECK: insertelement
5859 ; CHECK: extractelement
5960 ; CHECK: statepoint
6061 ; CHECK: gc.relocate
6162 ; CHECK-DAG: (%obj, %obj)
62 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
63 entry:
64 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %ptr, i32 0
65 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
66 call void @do_safepoint() [ "deopt"() ]
6367 ret i64 addrspace(1)* %obj
6468 }
65 define i64 addrspace(1)* @test4(i64 addrspace(1)* %ptr)
66 gc "statepoint-example" {
69
70 define i64 addrspace(1)* @test4(i64 addrspace(1)* %ptr) gc "statepoint-example" {
6771 ; CHECK-LABEL: test4
72 ; CHECK: statepoint
73 ; CHECK: gc.relocate
74 ; CHECK-DAG: ; (%ptr, %obj)
75 ; CHECK: gc.relocate
76 ; CHECK-DAG: ; (%ptr, %ptr)
77 ; When we can optimize an extractelement from a known
78 ; index and avoid introducing new base pointer instructions
6879 entry:
6980 %derived = getelementptr i64, i64 addrspace(1)* %ptr, i64 16
7081 %veca = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %derived, i32 0
7182 %vec = insertelement <2 x i64 addrspace(1)*> %veca, i64 addrspace(1)* %ptr, i32 1
7283 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
73 ; CHECK: statepoint
74 ; CHECK: gc.relocate
75 ; CHECK-DAG: ; (%ptr, %obj)
76 ; CHECK: gc.relocate
77 ; CHECK-DAG: ; (%ptr, %ptr)
78 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
84 call void @do_safepoint() [ "deopt"() ]
7985 ret i64 addrspace(1)* %obj
8086 }
8187
82 declare void @use(i64 addrspace(1)*)
88 declare void @use(i64 addrspace(1)*) "gc-leaf-function"
8389
84 ; When we can optimize an extractelement from a known
85 ; index and avoid introducing new base pointer instructions
86 define void @test5(i1 %cnd, i64 addrspace(1)* %obj)
87 gc "statepoint-example" {
90 define void @test5(i1 %cnd, i64 addrspace(1)* %obj) gc "statepoint-example" {
8891 ; CHECK-LABEL: @test5
8992 ; CHECK: gc.relocate
9093 ; CHECK-DAG: (%obj, %bdv)
94 ; When we fundementally have to duplicate
9195 entry:
9296 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
9397 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
9498 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
95 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
99 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
96100 call void @use(i64 addrspace(1)* %bdv)
97101 ret void
98102 }
99103
100 ; When we fundementally have to duplicate
101 define void @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 %idx)
102 gc "statepoint-example" {
104 define void @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" {
103105 ; CHECK-LABEL: @test6
104106 ; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
105107 ; CHECK: %vec.base = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj, i32 0, !is_base_value !0
109111 ; CHECK: gc.statepoint
110112 ; CHECK: gc.relocate
111113 ; CHECK-DAG: (%bdv.base, %bdv)
114 ; A more complicated example involving vector and scalar bases.
115 ; This is derived from a failing test case when we didn't have correct
116 ; insertelement handling.
112117 entry:
113118 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
114119 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
115120 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
116 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
121 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
117122 call void @use(i64 addrspace(1)* %bdv)
118123 ret void
119124 }
120125
121 ; A more complicated example involving vector and scalar bases.
122 ; This is derived from a failing test case when we didn't have correct
123 ; insertelement handling.
124 define i64 addrspace(1)* @test7(i1 %cnd, i64 addrspace(1)* %obj,
125 i64 addrspace(1)* %obj2)
126 gc "statepoint-example" {
126 define i64 addrspace(1)* @test7(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
127127 ; CHECK-LABEL: @test7
128128 entry:
129129 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 0
130130 br label %merge1
131 merge1:
131
132 merge1: ; preds = %merge1, %entry
132133 ; CHECK-LABEL: merge1:
133134 ; CHECK: vec2.base
134135 ; CHECK: vec2
139140 %gep = getelementptr i64, i64 addrspace(1)* %obj2, i64 1
140141 %vec3 = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
141142 br i1 %cnd, label %merge1, label %next1
142 next1:
143
144 next1: ; preds = %merge1
143145 ; CHECK-LABEL: next1:
144146 ; CHECK: bdv.base =
145147 ; CHECK: bdv =
146148 %bdv = extractelement <2 x i64 addrspace(1)*> %vec2, i32 0
147149 br label %merge
148 merge:
150
151 merge: ; preds = %merge, %next1
149152 ; CHECK-LABEL: merge:
150153 ; CHECK: %objb.base
151154 ; CHECK: %objb
152155 ; CHECK: gc.statepoint
153156 ; CHECK: gc.relocate
154157 ; CHECK-DAG: (%objb.base, %objb)
155
156158 %objb = phi i64 addrspace(1)* [ %obj, %next1 ], [ %bdv, %merge ]
157159 br i1 %cnd, label %merge, label %next
158 next:
159 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
160
161 next: ; preds = %merge
162 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
160163 ret i64 addrspace(1)* %objb
161164 }
162165
163
164166 declare void @do_safepoint()
165
166 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
0 ; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
1
2 declare void @g()
3 declare i32 @h()
4
5 define i32 addrspace(1)* @f0(i32 addrspace(1)* %arg) gc "statepoint-example" {
6 ; CHECK-LABEL: @f0(
7 entry:
8 ; CHECK: [[TOKEN_0:%[^ ]+]] = call token {{[^@]*}} @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
9 call void @g() [ "deopt"(i32 100) ]
10
11 ; CHECK: %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_0]], i32 8, i32 8)
12 ret i32 addrspace(1)* %arg
13 }
14
15 define i32 addrspace(1)* @f1(i32 addrspace(1)* %arg) gc "statepoint-example" personality i32 8 {
16 ; CHECK-LABEL: @f1(
17 entry:
18 ; CHECK: [[TOKEN_1:%[^ ]+]] = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
19 invoke void @g() [ "deopt"(i32 100) ] to label %normal_dest unwind label %unwind_dest
20
21 normal_dest:
22 ; CHECK: %arg.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_1]], i32 8, i32 8)
23 ret i32 addrspace(1)* %arg
24
25 unwind_dest:
26 %lpad = landingpad token cleanup
27 resume token undef
28 }
29
30 define i32 addrspace(1)* @f2(i32 addrspace(1)* %arg) gc "statepoint-example" {
31 ; CHECK-LABEL: @f2(
32 entry:
33 ; CHECK: [[TOKEN_2:%[^ ]+]] = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @h, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
34 %val = call i32 @h() [ "deopt"(i32 100) ]
35
36 ; CHECK: [[RESULT_F2:%[^ ]+]] = call i32 @llvm.experimental.gc.result.i32(token [[TOKEN_2]])
37 ; CHECK: %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_2]], i32 8, i32 8)
38 ; CHECK: %arg.relocated.casted = bitcast i8 addrspace(1)* %arg.relocated to i32 addrspace(1)*
39
40 store i32 %val, i32 addrspace(1)* %arg
41 ; CHECK: store i32 [[RESULT_F2]], i32 addrspace(1)* %arg.relocated.casted
42 ret i32 addrspace(1)* %arg
43 }
44
45 define i32 addrspace(1)* @f3(i32 addrspace(1)* %arg) gc "statepoint-example" personality i32 8 {
46 ; CHECK-LABEL: @f3(
47 entry:
48 ; CHECK: [[TOKEN_3:%[^ ]+]] = invoke token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @h, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
49 %val = invoke i32 @h() [ "deopt"(i32 100) ] to label %normal_dest unwind label %unwind_dest
50
51 normal_dest:
52 ; CHECK: [[RESULT_F3:%[^ ]+]] = call i32 @llvm.experimental.gc.result.i32(token [[TOKEN_3]])
53 ; CHECK: [[ARG_RELOCATED:%[^ ]+]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_3]], i32 8, i32 8)
54 ; CHECK: [[ARG_RELOCATED_CASTED:%[^ ]+]] = bitcast i8 addrspace(1)* [[ARG_RELOCATED]] to i32 addrspace(1)*
55
56 store i32 %val, i32 addrspace(1)* %arg
57
58 ; CHECK: store i32 [[RESULT_F3]], i32 addrspace(1)* [[ARG_RELOCATED_CASTED]]
59 ret i32 addrspace(1)* %arg
60
61 unwind_dest:
62 %lpad = landingpad token cleanup
63 resume token undef
64 }
65
66 define i32 addrspace(1)* @f4(i32 addrspace(1)* %arg) gc "statepoint-example" {
67 ; CHECK-LABEL: @f4(
68 entry:
69 ; CHECK: @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 1, i32 2, i32 400, i8 90,
70 call void @g() [ "gc-transition"(i32 400, i8 90) ]
71 ret i32 addrspace(1)* %arg
72 }
0 ; This is a collection of really basic tests for gc.statepoint rewriting.
1 ; RUN: opt %s -rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
1 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
2
3 ; Trivial relocation over a single call
24
35 declare void @foo()
46
5 ; Trivial relocation over a single call
67 define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
78 ; CHECK-LABEL: @test1
9 entry:
810 ; CHECK-LABEL: entry:
911 ; CHECK-NEXT: gc.statepoint
1012 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
11 entry:
12 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
13 ; Two safepoints in a row (i.e. consistent liveness)
14 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
1315 ret i8 addrspace(1)* %obj
1416 }
1517
16 ; Two safepoints in a row (i.e. consistent liveness)
1718 define i8 addrspace(1)* @test2(i8 addrspace(1)* %obj) gc "statepoint-example" {
1819 ; CHECK-LABEL: @test2
20 entry:
1921 ; CHECK-LABEL: entry:
2022 ; CHECK-NEXT: gc.statepoint
2123 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
2224 ; CHECK-NEXT: gc.statepoint
23 ; CHECK-NEXT: %obj.relocated1 = call coldcc i8 addrspace(1)*
24 entry:
25 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
26 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
25 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
26 ; A simple derived pointer
27 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
28 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
2729 ret i8 addrspace(1)* %obj
2830 }
2931
30 ; A simple derived pointer
3132 define i8 @test3(i8 addrspace(1)* %obj) gc "statepoint-example" {
33 entry:
3234 ; CHECK-LABEL: entry:
3335 ; CHECK-NEXT: getelementptr
3436 ; CHECK-NEXT: gc.statepoint
3638 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
3739 ; CHECK-NEXT: load i8, i8 addrspace(1)* %derived.relocated
3840 ; CHECK-NEXT: load i8, i8 addrspace(1)* %obj.relocated
39 entry:
41 ; Tests to make sure we visit both the taken and untaken predeccessor
42 ; of merge. This was a bug in the dataflow liveness at one point.
4043 %derived = getelementptr i8, i8 addrspace(1)* %obj, i64 10
41 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
42
44 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
4345 %a = load i8, i8 addrspace(1)* %derived
4446 %b = load i8, i8 addrspace(1)* %obj
4547 %c = sub i8 %a, %b
4648 ret i8 %c
4749 }
4850
49 ; Tests to make sure we visit both the taken and untaken predeccessor
50 ; of merge. This was a bug in the dataflow liveness at one point.
5151 define i8 addrspace(1)* @test4(i1 %cmp, i8 addrspace(1)* %obj) gc "statepoint-example" {
5252 entry:
5353 br i1 %cmp, label %taken, label %untaken
5454
55 taken:
55 taken: ; preds = %entry
5656 ; CHECK-LABEL: taken:
5757 ; CHECK-NEXT: gc.statepoint
5858 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
59 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
59 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
6060 br label %merge
6161
62 untaken:
62 untaken: ; preds = %entry
6363 ; CHECK-LABEL: untaken:
6464 ; CHECK-NEXT: gc.statepoint
65 ; CHECK-NEXT: %obj.relocated1 = call coldcc i8 addrspace(1)*
66 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
65 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
66 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
6767 br label %merge
6868
69 merge:
69 merge: ; preds = %untaken, %taken
7070 ; CHECK-LABEL: merge:
71 ; CHECK-NEXT: %.0 = phi i8 addrspace(1)* [ %obj.relocated, %taken ], [ %obj.relocated1, %untaken ]
71 ; CHECK-NEXT: %.0 = phi i8 addrspace(1)* [ %obj.relocated, %taken ], [ %obj.relocated2, %untaken ]
7272 ; CHECK-NEXT: ret i8 addrspace(1)* %.0
73 ; When run over a function which doesn't opt in, should do nothing!
7374 ret i8 addrspace(1)* %obj
7475 }
7576
76 ; When run over a function which doesn't opt in, should do nothing!
7777 define i8 addrspace(1)* @test5(i8 addrspace(1)* %obj) gc "ocaml" {
7878 ; CHECK-LABEL: @test5
79 entry:
7980 ; CHECK-LABEL: entry:
8081 ; CHECK-NEXT: gc.statepoint
8182 ; CHECK-NOT: %obj.relocated = call coldcc i8 addrspace(1)*
82 entry:
83 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
83 %0 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
8484 ret i8 addrspace(1)* %obj
8585 }
8686
87 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
87 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
0 ;; RUN: opt < %s -rewrite-statepoints-for-gc -S | FileCheck %s
1
2 ;; This test is to verify that gc_result from a call statepoint
3 ;; can have preceding phis in its parent basic block. Unlike
4 ;; invoke statepoint, call statepoint does not terminate the
5 ;; block, and thus its gc_result is in the same block with the
6 ;; call statepoint.
7
8 declare i32 @foo()
9
10 define i32 @test1(i1 %cond, i32 %a) gc "statepoint-example" {
11 entry:
12 br i1 %cond, label %branch1, label %branch2
13
14 branch1:
15 %b = add i32 %a, 1
16 br label %merge
17
18 branch2:
19 br label %merge
20
21 merge:
22 ;; CHECK: %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
23 ;; CHECK-NEXT: [[TOKEN:%[^ ]+]] = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @foo, i32 0, i32 0, i32 0, i32 0
24 ;; CHECK-NEXT: call i32 @llvm.experimental.gc.result.i32(token [[TOKEN]])
25 %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
26 %ret = call i32 @foo()
27 ret i32 %ret
28 }
29
30 ; This function is inlined when inserting a poll.
31 declare void @do_safepoint()
32 define void @gc.safepoint_poll() {
33 ; CHECK-LABEL: gc.safepoint_poll
34 entry:
35 call void @do_safepoint()
36 ret void
37 }
0 ; RUN: opt -rewrite-statepoints-for-gc -S < %s | FileCheck %s
11
22 ; A null test of a single value
3
34 define i1 @test(i8 addrspace(1)* %p, i1 %rare) gc "statepoint-example" {
45 ; CHECK-LABEL: @test
56 entry:
6 %cond = icmp eq i8 addrspace(1)* %p, null
7 br i1 %rare, label %safepoint, label %continue, !prof !0
8 safepoint:
9 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @safepoint, i32 0, i32 0, i32 0, i32 0)
10 br label %continue
11 continue:
7 %cond = icmp eq i8 addrspace(1)* %p, null
8 br i1 %rare, label %safepoint, label %continue, !prof !0
9
10 safepoint: ; preds = %entry
11 call void @safepoint() [ "deopt"() ]
12 br label %continue
13
14 continue: ; preds = %safepoint, %entry
1215 ; CHECK-LABEL: continue:
1316 ; CHECK: phi
1417 ; CHECK-DAG: [ %p.relocated, %safepoint ]
1518 ; CHECK-DAG: [ %p, %entry ]
1619 ; CHECK: %cond = icmp
1720 ; CHECK: br i1 %cond
18 br i1 %cond, label %taken, label %untaken
19 taken:
20 ret i1 true
21 untaken:
22 ret i1 false
21 ; Comparing two pointers
22 br i1 %cond, label %taken, label %untaken
23
24 taken: ; preds = %continue
25 ret i1 true
26
27 untaken: ; preds = %continue
28 ret i1 false
2329 }
2430
25 ; Comparing two pointers
26 define i1 @test2(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare)
27 gc "statepoint-example" {
31 define i1 @test2(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare) gc "statepoint-example" {
2832 ; CHECK-LABEL: @test2
29 entry:
30 %cond = icmp eq i8 addrspace(1)* %p, %q
31 br i1 %rare, label %safepoint, label %continue, !prof !0
32 safepoint:
33 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @safepoint, i32 0, i32 0, i32 0, i32 0)
34 br label %continue
35 continue:
33 entry:
34 %cond = icmp eq i8 addrspace(1)* %p, %q
35 br i1 %rare, label %safepoint, label %continue, !prof !0
36
37 safepoint: ; preds = %entry
38 call void @safepoint() [ "deopt"() ]
39 br label %continue
40
41 continue: ; preds = %safepoint, %entry
3642 ; CHECK-LABEL: continue:
3743 ; CHECK: phi
3844 ; CHECK-DAG: [ %q.relocated, %safepoint ]
4248 ; CHECK-DAG: [ %p, %entry ]
4349 ; CHECK: %cond = icmp
4450 ; CHECK: br i1 %cond
45 br i1 %cond, label %taken, label %untaken
46 taken:
47 ret i1 true
48 untaken:
49 ret i1 false
51 ; Sanity check that nothing bad happens if already last instruction
52 ; before terminator
53 br i1 %cond, label %taken, label %untaken
54
55 taken: ; preds = %continue
56 ret i1 true
57
58 untaken: ; preds = %continue
59 ret i1 false
5060 }
5161
52 ; Sanity check that nothing bad happens if already last instruction
53 ; before terminator
54 define i1 @test3(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare)
55 gc "statepoint-example" {
62 define i1 @test3(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare) gc "statepoint-example" {
5663 ; CHECK-LABEL: @test3
57 entry:
58 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @safepoint, i32 0, i32 0, i32 0, i32 0)
5964 ; CHECK: gc.statepoint
6065 ; CHECK: %cond = icmp
6166 ; CHECK: br i1 %cond
62 %cond = icmp eq i8 addrspace(1)* %p, %q
63 br i1 %cond, label %taken, label %untaken
64 taken:
65 ret i1 true
66 untaken:
67 ret i1 false
67 entry:
68 call void @safepoint() [ "deopt"() ]
69 %cond = icmp eq i8 addrspace(1)* %p, %q
70 br i1 %cond, label %taken, label %untaken
71
72 taken: ; preds = %entry
73 ret i1 true
74
75 untaken: ; preds = %entry
76 ret i1 false
6877 }
6978
7079 declare void @safepoint()
71 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
72
7380 !0 = !{!"branch_weights", i32 1, i32 10000}
None ; RUN: opt -S -rewrite-statepoints-for-gc %s | FileCheck %s
0 ; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
1
2 ; constants don't get relocated.
3 @G = addrspace(1) global i8 5
14
25 declare void @foo()
3 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
46
5 ; constants don't get relocated.
67 define i8 @test() gc "statepoint-example" {
78 ; CHECK-LABEL: @test
89 ; CHECK: gc.statepoint
910 ; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
11 ; Mostly just here to show reasonable code test can come from.
1012 entry:
11 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
13 call void @foo() [ "deopt"() ]
1214 %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
1315 ret i8 %res
1416 }
1517
16
17 ; Mostly just here to show reasonable code test can come from.
1818 define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
1919 ; CHECK-LABEL: @test2
2020 ; CHECK: gc.statepoint
2121 ; CHECK-NEXT: gc.relocate
2222 ; CHECK-NEXT: icmp
23 ; Globals don't move and thus don't get relocated
2324 entry:
24 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
25 call void @foo() [ "deopt"() ]
2526 %cmp = icmp eq i8 addrspace(1)* %p, null
2627 br i1 %cmp, label %taken, label %not_taken
2728
28 taken:
29 taken: ; preds = %not_taken, %entry
2930 ret i8 0
3031
31 not_taken:
32 not_taken: ; preds = %entry
3233 %cmp2 = icmp ne i8 addrspace(1)* %p, null
3334 br i1 %cmp2, label %taken, label %dead
3435
35 dead:
36 ; We see that dead can't be reached, but the optimizer might not. It's
37 ; completely legal for it to exploit the fact that if dead executed, %p
38 ; would have to equal null. This can produce intermediate states which
39 ; look like that of test above, even if arbitrary constant addresses aren't
40 ; legal in the source language
36 dead: ; preds = %not_taken
4137 %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
42 %res = load i8, i8addrspace(1)* %addr
38 %res = load i8, i8 addrspace(1)* %addr
4339 ret i8 %res
4440 }
4541
46 @G = addrspace(1) global i8 5
47
48 ; Globals don't move and thus don't get relocated
4942 define i8 @test3(i1 %always_true) gc "statepoint-example" {
5043 ; CHECK-LABEL: @test3
5144 ; CHECK: gc.statepoint
5245 ; CHECK-NEXT: load i8, i8 addrspace(1)* @G
5346 entry:
54 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
47 call void @foo() [ "deopt"() ]
5548 %res = load i8, i8 addrspace(1)* @G, align 1
5649 ret i8 %res
5750 }
58
59 ; Even for source languages without constant references, we can
60 ; see constants can show up along paths where the value is dead.
61 ; This is particular relevant when computing bases of PHIs.
62 define i8 addrspace(1)* @test4(i8 addrspace(1)* %p) gc "statepoint-example" {
63 ; CHECK-LABEL: @test4
64 entry:
65 %is_null = icmp eq i8 addrspace(1)* %p, null
66 br i1 %is_null, label %split, label %join
67
68 split:
69 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
70 %arg_value_addr.i = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
71 %arg_value_addr_casted.i = bitcast i8 addrspace(1)* %arg_value_addr.i to i8 addrspace(1)* addrspace(1)*
72 br label %join
73
74 join:
75 ; CHECK-LABEL: join
76 ; CHECK: %addr2.base =
77 %addr2 = phi i8 addrspace(1)* addrspace(1)* [ %arg_value_addr_casted.i, %split ], [ inttoptr (i64 8 to i8 addrspace(1)* addrspace(1)*), %entry ]
78 ;; NOTE: This particular example can be jump-threaded, but in general,
79 ;; we can't, and have to deal with the resulting IR.
80 br i1 %is_null, label %early-exit, label %use
81
82 early-exit:
83 ret i8 addrspace(1)* null
84
85 use:
86 ; CHECK-LABEL: use:
87 ; CHECK: gc.statepoint
88 ; CHECK: gc.relocate
89 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
90 %res = load i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)* %addr2, align 1
91 ret i8 addrspace(1)* %res
92 }
93
94 ; Globals don't move and thus don't get relocated
95 define i8 addrspace(1)* @test5(i1 %always_true) gc "statepoint-example" {
96 ; CHECK-LABEL: @test5
97 ; CHECK: gc.statepoint
98 ; CHECK-NEXT: %res = extractelement <2 x i8 addrspace(1)*> , i32 0
99 entry:
100 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
101 %res = extractelement <2 x i8 addrspace(1)*> , i32 0
102 ret i8 addrspace(1)* %res
103 }
+0
-25
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-1.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %merged_value base %merged_value.base
3
4 declare void @site_for_call_safpeoint()
5
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition) gc "statepoint-example" {
7 entry:
8 br i1 %runtime_condition, label %here, label %there
9
10 here: ; preds = %entry
11 %x = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
12 br label %merge
13
14 there: ; preds = %entry
15 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
16 br label %merge
17
18 merge: ; preds = %there, %here
19 ; CHECK-LABEL: merge:
20 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %here ], [ %base_obj_y, %there ]
21 %merged_value = phi i64 addrspace(1)* [ %x, %here ], [ %y, %there ]
22 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
23 ret i64 addrspace(1)* %merged_value
24 }
+0
-35
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-10.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2
3 declare i1 @runtime_value() "gc-leaf-function"
4
5 declare void @do_safepoint()
6
7 define void @select_of_phi(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y) gc "statepoint-example" {
8 entry:
9 br label %loop
10
11 loop: ; preds = %merge, %entry
12 %current_x = phi i64 addrspace(1)* [ %base_obj_x, %entry ], [ %next_x, %merge ]
13 %current_y = phi i64 addrspace(1)* [ %base_obj_y, %entry ], [ %next_y, %merge ]
14 %current = phi i64 addrspace(1)* [ null, %entry ], [ %next, %merge ]
15 %condition = call i1 @runtime_value()
16 %next_x = getelementptr i64, i64 addrspace(1)* %current_x, i32 1
17 %next_y = getelementptr i64, i64 addrspace(1)* %current_y, i32 1
18 br i1 %condition, label %true, label %false
19
20 true: ; preds = %loop
21 br label %merge
22
23 false: ; preds = %loop
24 br label %merge
25
26 merge: ; preds = %false, %true
27 %next = phi i64 addrspace(1)* [ %next_x, %true ], [ %next_y, %false ]
28 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
29 br label %loop
30 }
31 ; CHECK: Base Pairs (w/o Relocation):
32 ; CHECK-DAG: derived %next base %next.base
33 ; CHECK-DAG: derived %next_x base %base_obj_x
34 ; CHECK-DAG: derived %next_y base %base_obj_y
+0
-24
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-11.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %next base %base_obj
3
4 declare void @do_safepoint()
5
6 define void @test(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
7 entry:
8 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
9 br label %loop
10
11 loop: ; preds = %loop, %entry
12 ; CHECK-LABEL: loop:
13 ; CHECK: phi i64 addrspace(1)*
14 ; CHECK-DAG: [ %base_obj.relocated.casted, %loop ]
15 ; CHECK-DAG: [ %base_obj, %entry ]
16 ; CHECK: %current = phi i64 addrspace(1)*
17 ; CHECK-DAG: [ %obj, %entry ]
18 ; CHECK-DAG: [ %next.relocated.casted, %loop ]
19 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
20 %next = getelementptr i64, i64 addrspace(1)* %current, i32 1
21 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
22 br label %loop
23 }
+0
-20
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-12.ll less more
None ; RUN: opt < %s -rs4gc-use-deopt-bundles -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %select base @global
3
4 @global = external addrspace(1) global i8
5
6 define i8 @test(i1 %cond) gc "statepoint-example" {
7 %derived1 = getelementptr i8, i8 addrspace(1)* @global, i64 1
8 %derived2 = getelementptr i8, i8 addrspace(1)* @global, i64 2
9 %select = select i1 %cond, i8 addrspace(1)* %derived1, i8 addrspace(1)* %derived2
10 call void @extern()
11 ; CHECK-NOT: relocate
12 ; CHECK: %load = load i8, i8 addrspace(1)* %select
13 %load = load i8, i8 addrspace(1)* %select
14 ret i8 %load
15 }
16
17 declare void @extern() gc "statepoint-example"
18
19 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
+0
-19
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-13.ll less more
None ; RUN: opt < %s -rs4gc-use-deopt-bundles -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %derived base @global
3
4 @global = external addrspace(1) global i8
5
6 define i8 @test(i64 %offset) gc "statepoint-example" {
7 %derived = getelementptr i8, i8 addrspace(1)* @global, i64 %offset
8 call void @extern()
9 ; CHECK-NOT: relocate
10 ; CHECK-NOT: remat
11 ; CHECK: %load = load i8, i8 addrspace(1)* %derived
12 %load = load i8, i8 addrspace(1)* %derived
13 ret i8 %load
14 }
15
16 declare void @extern() gc "statepoint-example"
17
18 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
+0
-19
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-2.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %merged_value base %base_obj
3
4 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj, i1 %runtime_condition) gc "statepoint-example" {
5 entry:
6 br i1 %runtime_condition, label %merge, label %there
7
8 there: ; preds = %entry
9 %derived_obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
10 br label %merge
11
12 merge: ; preds = %there, %entry
13 %merged_value = phi i64 addrspace(1)* [ %base_obj, %entry ], [ %derived_obj, %there ]
14 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
15 ret i64 addrspace(1)* %merged_value
16 }
17
18 declare void @foo()
+0
-19
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-3.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %next.i64 base %base_obj
3
4 define void @test(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
5 entry:
6 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
7 br label %loop
8
9 loop: ; preds = %loop, %entry
10 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next.i64, %loop ]
11 %current.i32 = bitcast i64 addrspace(1)* %current to i32 addrspace(1)*
12 %next.i32 = getelementptr i32, i32 addrspace(1)* %current.i32, i32 1
13 %next.i64 = bitcast i32 addrspace(1)* %next.i32 to i64 addrspace(1)*
14 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
15 br label %loop
16 }
17
18 declare void @do_safepoint()
+0
-44
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-4.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %obj_to_consume base %obj_to_consume
3
4 declare void @foo()
5
6 declare i64 addrspace(1)* @generate_obj()
7
8 declare void @consume_obj(i64 addrspace(1)*)
9
10 define void @test(i32 %condition) gc "statepoint-example" {
11 entry:
12 br label %loop
13
14 loop: ; preds = %merge.split, %entry
15 ; CHECK: loop:
16 ; CHECK: [[TOKEN_0:%[^ ]+]] = call token (i64, i32, i64 addrspace(1)* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* ()* @generate_obj, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i3
17 ; CHECK-NEXT: [[RESULT_0:%[^ ]+]] = call i64 addrspace(1)* @llvm.experimental.gc.result
18 %0 = call i64 addrspace(1)* @generate_obj() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
19 switch i32 %condition, label %dest_a [
20 i32 0, label %dest_b
21 i32 1, label %dest_c
22 ]
23
24 dest_a: ; preds = %loop
25 br label %merge
26
27 dest_b: ; preds = %loop
28 br label %merge
29
30 dest_c: ; preds = %loop
31 br label %merge
32
33 merge: ; preds = %dest_c, %dest_b, %dest_a
34 ; CHECK: merge:
35 ; CHECK: %obj_to_consume = phi i64 addrspace(1)* [ [[RESULT_0]], %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
36 %obj_to_consume = phi i64 addrspace(1)* [ %0, %dest_a ], [ null, %dest_b ], [ null, %dest_c ]
37 call void @consume_obj(i64 addrspace(1)* %obj_to_consume) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
38 br label %merge.split
39
40 merge.split: ; preds = %merge
41 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
42 br label %loop
43 }
+0
-28
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-5.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %merged_value base %merged_value.base
3
4 declare void @foo()
5
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition) gc "statepoint-example" {
7 entry:
8 br i1 %runtime_condition, label %here, label %there
9
10 here: ; preds = %entry
11 br label %bump
12
13 bump: ; preds = %here
14 br label %merge
15
16 there: ; preds = %entry
17 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
18 br label %merge
19
20 merge: ; preds = %there, %bump
21 ; CHECK: merge:
22 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %base_obj_y, %there ]
23 ; CHECK-NEXT: %merged_value = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %y, %there ]
24 %merged_value = phi i64 addrspace(1)* [ %base_obj_x, %bump ], [ %y, %there ]
25 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
26 ret i64 addrspace(1)* %merged_value
27 }
+0
-37
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-6.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %merged_value base %merged_value.base
3
4 declare void @site_for_call_safpeoint()
5
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition_x, i1 %runtime_condition_y) gc "statepoint-example" {
7 entry:
8 br i1 %runtime_condition_x, label %here, label %there
9
10 here: ; preds = %entry
11 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
12
13 bump_here_a: ; preds = %here
14 %x_a = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
15 br label %merge_here
16
17 bump_here_b: ; preds = %here
18 %x_b = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 2
19 br label %merge_here
20
21 merge_here: ; preds = %bump_here_b, %bump_here_a
22 %x = phi i64 addrspace(1)* [ %x_a, %bump_here_a ], [ %x_b, %bump_here_b ]
23 br label %merge
24
25 there: ; preds = %entry
26 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
27 br label %merge
28
29 merge: ; preds = %there, %merge_here
30 ; CHECK: merge:
31 ; CHECK: %merged_value.base = phi i64 addrspace(1)* [ %base_obj_x, %merge_here ], [ %base_obj_y, %there ]
32 ; CHECK-NEXT: %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
33 %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
34 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
35 ret i64 addrspace(1)* %merged_value
36 }
+0
-45
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-7.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %merged_value base %merged_value.base
3
4 declare void @site_for_call_safpeoint()
5
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition_x, i1 %runtime_condition_y) gc "statepoint-example" {
7 entry:
8 br i1 %runtime_condition_x, label %here, label %there
9
10 here: ; preds = %entry
11 br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
12
13 bump_here_a: ; preds = %here
14 %x_a = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
15 br label %merge_here
16
17 bump_here_b: ; preds = %here
18 %x_b = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 2
19 br label %merge_here
20
21 merge_here: ; preds = %bump_here_b, %bump_here_a
22 ; CHECK: merge_here:
23 ; CHECK-DAG: %x.base
24 ; CHECK-DAG: phi i64 addrspace(1)*
25 ; CHECK-DAG: [ %base_obj_x, %bump_here_a ]
26 ; CHECK-DAG: [ %base_obj_y, %bump_here_b ]
27 %x = phi i64 addrspace(1)* [ %x_a, %bump_here_a ], [ %x_b, %bump_here_b ]
28 br label %merge
29
30 there: ; preds = %entry
31 %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
32 br label %merge
33
34 merge: ; preds = %there, %merge_here
35 ; CHECK: merge:
36 ; CHECK-DAG: %merged_value.base
37 ; CHECK-DAG: phi i64 addrspace(1)*
38 ; CHECK-DAG: %merge_here
39 ; CHECK-DAG: [ %base_obj_y, %there ]
40 ; CHECK: %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
41 %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
42 call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
43 ret i64 addrspace(1)* %merged_value
44 }
+0
-37
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-8.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %next_element_ptr base %array_obj
3
4 define i32 @null_in_array(i64 addrspace(1)* %array_obj) gc "statepoint-example" {
5 entry:
6 %array_len_pointer.i64 = getelementptr i64, i64 addrspace(1)* %array_obj, i32 1
7 %array_len_pointer.i32 = bitcast i64 addrspace(1)* %array_len_pointer.i64 to i32 addrspace(1)*
8 %array_len = load i32, i32 addrspace(1)* %array_len_pointer.i32
9 %array_elems = bitcast i32 addrspace(1)* %array_len_pointer.i32 to i64 addrspace(1)* addrspace(1)*
10 br label %loop_check
11
12 loop_check: ; preds = %loop_back, %entry
13 %index = phi i32 [ 0, %entry ], [ %next_index, %loop_back ]
14 %current_element_ptr = phi i64 addrspace(1)* addrspace(1)* [ %array_elems, %entry ], [ %next_element_ptr, %loop_back ]
15 %index_lt = icmp ult i32 %index, %array_len
16 br i1 %index_lt, label %check_for_null, label %not_found
17
18 check_for_null: ; preds = %loop_check
19 %current_element = load i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr
20 %is_null = icmp eq i64 addrspace(1)* %current_element, null
21 br i1 %is_null, label %found, label %loop_back
22
23 loop_back: ; preds = %check_for_null
24 %next_element_ptr = getelementptr i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr, i32 1
25 %next_index = add i32 %index, 1
26 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
27 br label %loop_check
28
29 not_found: ; preds = %loop_check
30 ret i32 -1
31
32 found: ; preds = %check_for_null
33 ret i32 %index
34 }
35
36 declare void @do_safepoint()
+0
-20
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers-9.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-print-base-pointers -S 2>&1 | FileCheck %s
1
2 ; CHECK: derived %next base %base_obj
3
4 declare i1 @runtime_value() "gc-leaf-function"
5
6 define void @maybe_GEP(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
7 entry:
8 br label %loop
9
10 loop: ; preds = %loop, %entry
11 %current = phi i64 addrspace(1)* [ %base_obj, %entry ], [ %next, %loop ]
12 %condition = call i1 @runtime_value()
13 %maybe_next = getelementptr i64, i64 addrspace(1)* %current, i32 1
14 %next = select i1 %condition, i64 addrspace(1)* %maybe_next, i64 addrspace(1)* %current
15 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
16 br label %loop
17 }
18
19 declare void @do_safepoint()
+0
-151
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-pointers.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S 2>&1 | FileCheck %s
1
2 ; The rewriting needs to make %obj loop variant by inserting a phi
3 ; of the original value and it's relocation.
4
5 declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
6
7 declare void @use_obj(i64 addrspace(1)*) "gc-leaf-function"
8
9 define void @def_use_safepoint() gc "statepoint-example" {
10 ; CHECK-LABEL: def_use_safepoint
11 ; CHECK: phi i64 addrspace(1)*
12 ; CHECK-DAG: [ %obj.relocated.casted, %loop ]
13 ; CHECK-DAG: [ %obj, %entry ]
14 entry:
15 %obj = call i64 addrspace(1)* @generate_obj()
16 br label %loop
17
18 loop: ; preds = %loop, %entry
19 call void @use_obj(i64 addrspace(1)* %obj)
20 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
21 br label %loop
22 }
23
24 declare void @do_safepoint()
25
26 declare void @parse_point(i64 addrspace(1)*)
27
28 define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
29 ; CHECK-LABEL: test1
30 entry:
31 br i1 undef, label %left, label %right
32
33 left: ; preds = %entry
34 ; CHECK: left:
35 ; CHECK-NEXT: %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
36 ; CHECK-NEXT: [[CAST_L:%.*]] = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
37 ; Our safepoint placement pass calls removeUnreachableBlocks, which does a bunch
38 ; of simplifications to branch instructions. This bug is visible only when
39 ; there are multiple branches into the same block from the same predecessor, and
40 ; the following ceremony is to make that artefact survive a call to
41 ; removeUnreachableBlocks. As an example, "br i1 undef, label %merge, label %merge"
42 ; will get simplified to "br label %merge" by removeUnreachableBlocks.
43 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
44 switch i32 %unknown, label %right [
45 i32 0, label %merge
46 i32 1, label %merge
47 i32 5, label %merge
48 i32 3, label %right
49 ]
50
51 right: ; preds = %left, %left, %entry
52 ; CHECK: right:
53 ; CHECK-NEXT: %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
54 ; CHECK-NEXT: [[CAST_R:%.*]] = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
55 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
56 br label %merge
57
58 merge: ; preds = %right, %left, %left, %left
59 ; CHECK: merge:
60 ; CHECK-NEXT: %value.base = phi i64 addrspace(1)* [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_R]], %right ], !is_base_value !0
61 %value = phi i64 addrspace(1)* [ %a.cast, %left ], [ %a.cast, %left ], [ %a.cast, %left ], [ %b.cast, %right ]
62 call void @parse_point(i64 addrspace(1)* %value) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0) ]
63 ret i64 addrspace(1)* %value
64 }
65
66 ;; The purpose of this test is to ensure that when two live values share a
67 ;; base defining value with inherent conflicts, we end up with a *single*
68 ;; base phi/select per such node. This is testing an optimization, not a
69 ;; fundemental correctness criteria
70 define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
71 ; CHECK-LABEL: @test2
72 entry:
73 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
74 br label %loop
75 ; CHECK-LABEL: loop
76 ; CHECK: %current.base = phi i64 addrspace(1)*
77 ; CHECK-DAG: [ %base_obj, %entry ]
78
79 ; Given the two selects are equivelent, so are their base phis - ideally,
80 ; we'd have commoned these, but that's a missed optimization, not correctness.
81 ; CHECK-DAG: [ [[DISCARD:%.*.base.relocated.casted]], %loop ]
82 ; CHECK-NOT: extra.base
83 ; CHECK: next = select
84 ; CHECK: extra2.base = select
85 ; CHECK: extra2 = select
86 ; CHECK: statepoint
87 ;; Both 'next' and 'extra2' are live across the backedge safepoint...
88
89 loop: ; preds = %loop, %entry
90 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
91 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
92 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
93 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
94 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
95 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
96 br label %loop
97 }
98
99 define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
100 ; CHECK-LABEL: @test3
101 entry:
102 br i1 %cnd, label %merge, label %taken
103
104 taken: ; preds = %entry
105 br label %merge
106
107 merge: ; preds = %taken, %entry
108 ; CHECK-LABEL: merge:
109 ; CHECK-NEXT: %bdv = phi
110 ; CHECK-NEXT: gc.statepoint
111 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %taken ]
112 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
113 ret i64 addrspace(1)* %bdv
114 }
115
116 define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
117 ; CHECK-LABEL: @test4
118 entry:
119 br i1 %cnd, label %merge, label %taken
120
121 taken: ; preds = %entry
122 br label %merge
123
124 merge: ; preds = %taken, %entry
125 ; CHECK-LABEL: merge:
126 ; CHECK-NEXT: %bdv = phi
127 ; CHECK-NEXT: gc.statepoint
128 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj, %taken ]
129 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
130 ret i64 addrspace(1)* %bdv
131 }
132
133 define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
134 ; CHECK-LABEL: @test5
135 entry:
136 br label %merge
137
138 merge: ; preds = %merge, %entry
139 ; CHECK-LABEL: merge:
140 ; CHECK-NEXT: %bdv = phi
141 ; CHECK-NEXT: br i1
142 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
143 br i1 %cnd, label %merge, label %next
144
145 next: ; preds = %merge
146 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
147 ret i64 addrspace(1)* %bdv
148 }
149
150 declare void @foo()
+0
-167
test/Transforms/RewriteStatepointsForGC/deopt-bundles/base-vector.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S | FileCheck %s
1
2
3 define i64 addrspace(1)* @test(<2 x i64 addrspace(1)*> %vec, i32 %idx) gc "statepoint-example" {
4 ; CHECK-LABEL: @test
5 ; CHECK: extractelement
6 ; CHECK: extractelement
7 ; CHECK: statepoint
8 ; CHECK: gc.relocate
9 ; CHECK-DAG: ; (%base_ee, %base_ee)
10 ; CHECK: gc.relocate
11 ; CHECK-DAG: ; (%base_ee, %obj)
12 ; Note that the second extractelement is actually redundant here. A correct output would
13 ; be to reuse the existing obj as a base since it is actually a base pointer.
14 entry:
15 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx
16 call void @do_safepoint() [ "deopt"() ]
17 ret i64 addrspace(1)* %obj
18 }
19
20 define i64 addrspace(1)* @test2(<2 x i64 addrspace(1)*>* %ptr, i1 %cnd, i32 %idx1, i32 %idx2) gc "statepoint-example" {
21 ; CHECK-LABEL: test2
22 entry:
23 br i1 %cnd, label %taken, label %untaken
24
25 taken: ; preds = %entry
26 %obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
27 br label %merge
28
29 untaken: ; preds = %entry
30 %objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
31 br label %merge
32
33 merge: ; preds = %untaken, %taken
34 %vec = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ]
35 br i1 %cnd, label %taken2, label %untaken2
36
37 taken2: ; preds = %merge
38 %obj0 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx1
39 br label %merge2
40
41 untaken2: ; preds = %merge
42 %obj1 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx2
43 br label %merge2
44
45 merge2: ; preds = %untaken2, %taken2
46 ; CHECK-LABEL: merge2:
47 ; CHECK-NEXT: %obj = phi i64 addrspace(1)*
48 ; CHECK-NEXT: statepoint
49 ; CHECK: gc.relocate
50 ; CHECK-DAG: ; (%obj, %obj)
51 %obj = phi i64 addrspace(1)* [ %obj0, %taken2 ], [ %obj1, %untaken2 ]
52 call void @do_safepoint() [ "deopt"() ]
53 ret i64 addrspace(1)* %obj
54 }
55
56 define i64 addrspace(1)* @test3(i64 addrspace(1)* %ptr) gc "statepoint-example" {
57 ; CHECK-LABEL: test3
58 ; CHECK: insertelement
59 ; CHECK: extractelement
60 ; CHECK: statepoint
61 ; CHECK: gc.relocate
62 ; CHECK-DAG: (%obj, %obj)
63 entry:
64 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %ptr, i32 0
65 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
66 call void @do_safepoint() [ "deopt"() ]
67 ret i64 addrspace(1)* %obj
68 }
69
70 define i64 addrspace(1)* @test4(i64 addrspace(1)* %ptr) gc "statepoint-example" {
71 ; CHECK-LABEL: test4
72 ; CHECK: statepoint
73 ; CHECK: gc.relocate
74 ; CHECK-DAG: ; (%ptr, %obj)
75 ; CHECK: gc.relocate
76 ; CHECK-DAG: ; (%ptr, %ptr)
77 ; When we can optimize an extractelement from a known
78 ; index and avoid introducing new base pointer instructions
79 entry:
80 %derived = getelementptr i64, i64 addrspace(1)* %ptr, i64 16
81 %veca = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %derived, i32 0
82 %vec = insertelement <2 x i64 addrspace(1)*> %veca, i64 addrspace(1)* %ptr, i32 1
83 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
84 call void @do_safepoint() [ "deopt"() ]
85 ret i64 addrspace(1)* %obj
86 }
87
88 declare void @use(i64 addrspace(1)*) "gc-leaf-function"
89
90 define void @test5(i1 %cnd, i64 addrspace(1)* %obj) gc "statepoint-example" {
91 ; CHECK-LABEL: @test5
92 ; CHECK: gc.relocate
93 ; CHECK-DAG: (%obj, %bdv)
94 ; When we fundementally have to duplicate
95 entry:
96 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
97 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
98 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
99 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
100 call void @use(i64 addrspace(1)* %bdv)
101 ret void
102 }
103
104 define void @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" {
105 ; CHECK-LABEL: @test6
106 ; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
107 ; CHECK: %vec.base = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj, i32 0, !is_base_value !0
108 ; CHECK: %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
109 ; CHECK: %bdv.base = extractelement <2 x i64 addrspace(1)*> %vec.base, i64 %idx, !is_base_value !0
110 ; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
111 ; CHECK: gc.statepoint
112 ; CHECK: gc.relocate
113 ; CHECK-DAG: (%bdv.base, %bdv)
114 ; A more complicated example involving vector and scalar bases.
115 ; This is derived from a failing test case when we didn't have correct
116 ; insertelement handling.
117 entry:
118 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
119 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
120 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
121 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
122 call void @use(i64 addrspace(1)* %bdv)
123 ret void
124 }
125
126 define i64 addrspace(1)* @test7(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
127 ; CHECK-LABEL: @test7
128 entry:
129 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 0
130 br label %merge1
131
132 merge1: ; preds = %merge1, %entry
133 ; CHECK-LABEL: merge1:
134 ; CHECK: vec2.base
135 ; CHECK: vec2
136 ; CHECK: gep
137 ; CHECK: vec3.base
138 ; CHECK: vec3
139 %vec2 = phi <2 x i64 addrspace(1)*> [ %vec, %entry ], [ %vec3, %merge1 ]
140 %gep = getelementptr i64, i64 addrspace(1)* %obj2, i64 1
141 %vec3 = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
142 br i1 %cnd, label %merge1, label %next1
143
144 next1: ; preds = %merge1
145 ; CHECK-LABEL: next1:
146 ; CHECK: bdv.base =
147 ; CHECK: bdv =
148 %bdv = extractelement <2 x i64 addrspace(1)*> %vec2, i32 0
149 br label %merge
150
151 merge: ; preds = %merge, %next1
152 ; CHECK-LABEL: merge:
153 ; CHECK: %objb.base
154 ; CHECK: %objb
155 ; CHECK: gc.statepoint
156 ; CHECK: gc.relocate
157 ; CHECK-DAG: (%objb.base, %objb)
158 %objb = phi i64 addrspace(1)* [ %obj, %next1 ], [ %bdv, %merge ]
159 br i1 %cnd, label %merge, label %next
160
161 next: ; preds = %merge
162 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
163 ret i64 addrspace(1)* %objb
164 }
165
166 declare void @do_safepoint()
+0
-73
test/Transforms/RewriteStatepointsForGC/deopt-bundles/basic.ll less more
None ; RUN: opt -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles < %s | FileCheck %s
1
2 declare void @g()
3 declare i32 @h()
4
5 define i32 addrspace(1)* @f0(i32 addrspace(1)* %arg) gc "statepoint-example" {
6 ; CHECK-LABEL: @f0(
7 entry:
8 ; CHECK: [[TOKEN_0:%[^ ]+]] = call token {{[^@]*}} @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
9 call void @g() [ "deopt"(i32 100) ]
10
11 ; CHECK: %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_0]], i32 8, i32 8)
12 ret i32 addrspace(1)* %arg
13 }
14
15 define i32 addrspace(1)* @f1(i32 addrspace(1)* %arg) gc "statepoint-example" personality i32 8 {
16 ; CHECK-LABEL: @f1(
17 entry:
18 ; CHECK: [[TOKEN_1:%[^ ]+]] = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
19 invoke void @g() [ "deopt"(i32 100) ] to label %normal_dest unwind label %unwind_dest
20
21 normal_dest:
22 ; CHECK: %arg.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_1]], i32 8, i32 8)
23 ret i32 addrspace(1)* %arg
24
25 unwind_dest:
26 %lpad = landingpad token cleanup
27 resume token undef
28 }
29
30 define i32 addrspace(1)* @f2(i32 addrspace(1)* %arg) gc "statepoint-example" {
31 ; CHECK-LABEL: @f2(
32 entry:
33 ; CHECK: [[TOKEN_2:%[^ ]+]] = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @h, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
34 %val = call i32 @h() [ "deopt"(i32 100) ]
35
36 ; CHECK: [[RESULT_F2:%[^ ]+]] = call i32 @llvm.experimental.gc.result.i32(token [[TOKEN_2]])
37 ; CHECK: %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_2]], i32 8, i32 8)
38 ; CHECK: %arg.relocated.casted = bitcast i8 addrspace(1)* %arg.relocated to i32 addrspace(1)*
39
40 store i32 %val, i32 addrspace(1)* %arg
41 ; CHECK: store i32 [[RESULT_F2]], i32 addrspace(1)* %arg.relocated.casted
42 ret i32 addrspace(1)* %arg
43 }
44
45 define i32 addrspace(1)* @f3(i32 addrspace(1)* %arg) gc "statepoint-example" personality i32 8 {
46 ; CHECK-LABEL: @f3(
47 entry:
48 ; CHECK: [[TOKEN_3:%[^ ]+]] = invoke token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @h, i32 0, i32 0, i32 0, i32 1, i32 100, i32 addrspace(1)* %arg)
49 %val = invoke i32 @h() [ "deopt"(i32 100) ] to label %normal_dest unwind label %unwind_dest
50
51 normal_dest:
52 ; CHECK: [[RESULT_F3:%[^ ]+]] = call i32 @llvm.experimental.gc.result.i32(token [[TOKEN_3]])
53 ; CHECK: [[ARG_RELOCATED:%[^ ]+]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[TOKEN_3]], i32 8, i32 8)
54 ; CHECK: [[ARG_RELOCATED_CASTED:%[^ ]+]] = bitcast i8 addrspace(1)* [[ARG_RELOCATED]] to i32 addrspace(1)*
55
56 store i32 %val, i32 addrspace(1)* %arg
57
58 ; CHECK: store i32 [[RESULT_F3]], i32 addrspace(1)* [[ARG_RELOCATED_CASTED]]
59 ret i32 addrspace(1)* %arg
60
61 unwind_dest:
62 %lpad = landingpad token cleanup
63 resume token undef
64 }
65
66 define i32 addrspace(1)* @f4(i32 addrspace(1)* %arg) gc "statepoint-example" {
67 ; CHECK-LABEL: @f4(
68 entry:
69 ; CHECK: @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 1, i32 2, i32 400, i8 90,
70 call void @g() [ "gc-transition"(i32 400, i8 90) ]
71 ret i32 addrspace(1)* %arg
72 }
+0
-88
test/Transforms/RewriteStatepointsForGC/deopt-bundles/basics.ll less more
None ; This is a collection of really basic tests for gc.statepoint rewriting.
1 ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-rematerialization-threshold=0 -S | FileCheck %s
2
3 ; Trivial relocation over a single call
4
5 declare void @foo()
6
7 define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
8 ; CHECK-LABEL: @test1
9 entry:
10 ; CHECK-LABEL: entry:
11 ; CHECK-NEXT: gc.statepoint
12 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
13 ; Two safepoints in a row (i.e. consistent liveness)
14 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
15 ret i8 addrspace(1)* %obj
16 }
17
18 define i8 addrspace(1)* @test2(i8 addrspace(1)* %obj) gc "statepoint-example" {
19 ; CHECK-LABEL: @test2
20 entry:
21 ; CHECK-LABEL: entry:
22 ; CHECK-NEXT: gc.statepoint
23 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
24 ; CHECK-NEXT: gc.statepoint
25 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
26 ; A simple derived pointer
27 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
28 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
29 ret i8 addrspace(1)* %obj
30 }
31
32 define i8 @test3(i8 addrspace(1)* %obj) gc "statepoint-example" {
33 entry:
34 ; CHECK-LABEL: entry:
35 ; CHECK-NEXT: getelementptr
36 ; CHECK-NEXT: gc.statepoint
37 ; CHECK-NEXT: %derived.relocated = call coldcc i8 addrspace(1)*
38 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
39 ; CHECK-NEXT: load i8, i8 addrspace(1)* %derived.relocated
40 ; CHECK-NEXT: load i8, i8 addrspace(1)* %obj.relocated
41 ; Tests to make sure we visit both the taken and untaken predeccessor
42 ; of merge. This was a bug in the dataflow liveness at one point.
43 %derived = getelementptr i8, i8 addrspace(1)* %obj, i64 10
44 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
45 %a = load i8, i8 addrspace(1)* %derived
46 %b = load i8, i8 addrspace(1)* %obj
47 %c = sub i8 %a, %b
48 ret i8 %c
49 }
50
51 define i8 addrspace(1)* @test4(i1 %cmp, i8 addrspace(1)* %obj) gc "statepoint-example" {
52 entry:
53 br i1 %cmp, label %taken, label %untaken
54
55 taken: ; preds = %entry
56 ; CHECK-LABEL: taken:
57 ; CHECK-NEXT: gc.statepoint
58 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
59 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
60 br label %merge
61
62 untaken: ; preds = %entry
63 ; CHECK-LABEL: untaken:
64 ; CHECK-NEXT: gc.statepoint
65 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
66 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
67 br label %merge
68
69 merge: ; preds = %untaken, %taken
70 ; CHECK-LABEL: merge:
71 ; CHECK-NEXT: %.0 = phi i8 addrspace(1)* [ %obj.relocated, %taken ], [ %obj.relocated2, %untaken ]
72 ; CHECK-NEXT: ret i8 addrspace(1)* %.0
73 ; When run over a function which doesn't opt in, should do nothing!
74 ret i8 addrspace(1)* %obj
75 }
76
77 define i8 addrspace(1)* @test5(i8 addrspace(1)* %obj) gc "ocaml" {
78 ; CHECK-LABEL: @test5
79 entry:
80 ; CHECK-LABEL: entry:
81 ; CHECK-NEXT: gc.statepoint
82 ; CHECK-NOT: %obj.relocated = call coldcc i8 addrspace(1)*
83 %0 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
84 ret i8 addrspace(1)* %obj
85 }
86
87 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
+0
-38
test/Transforms/RewriteStatepointsForGC/deopt-bundles/call-gc-result.ll less more
None ;; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S | FileCheck %s
1
2 ;; This test is to verify that gc_result from a call statepoint
3 ;; can have preceding phis in its parent basic block. Unlike
4 ;; invoke statepoint, call statepoint does not terminate the
5 ;; block, and thus its gc_result is in the same block with the
6 ;; call statepoint.
7
8 declare i32 @foo()
9
10 define i32 @test1(i1 %cond, i32 %a) gc "statepoint-example" {
11 entry:
12 br i1 %cond, label %branch1, label %branch2
13
14 branch1:
15 %b = add i32 %a, 1
16 br label %merge
17
18 branch2:
19 br label %merge
20
21 merge:
22 ;; CHECK: %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
23 ;; CHECK-NEXT: [[TOKEN:%[^ ]+]] = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @foo, i32 0, i32 0, i32 0, i32 0
24 ;; CHECK-NEXT: call i32 @llvm.experimental.gc.result.i32(token [[TOKEN]])
25 %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
26 %ret = call i32 @foo()
27 ret i32 %ret
28 }
29
30 ; This function is inlined when inserting a poll.
31 declare void @do_safepoint()
32 define void @gc.safepoint_poll() {
33 ; CHECK-LABEL: gc.safepoint_poll
34 entry:
35 call void @do_safepoint()
36 ret void
37 }
+0
-81
test/Transforms/RewriteStatepointsForGC/deopt-bundles/codegen-cond.ll less more
None ; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S < %s | FileCheck %s
1
2 ; A null test of a single value
3
4 define i1 @test(i8 addrspace(1)* %p, i1 %rare) gc "statepoint-example" {
5 ; CHECK-LABEL: @test
6 entry:
7 %cond = icmp eq i8 addrspace(1)* %p, null
8 br i1 %rare, label %safepoint, label %continue, !prof !0
9
10 safepoint: ; preds = %entry
11 call void @safepoint() [ "deopt"() ]
12 br label %continue
13
14 continue: ; preds = %safepoint, %entry
15 ; CHECK-LABEL: continue:
16 ; CHECK: phi
17 ; CHECK-DAG: [ %p.relocated, %safepoint ]
18 ; CHECK-DAG: [ %p, %entry ]
19 ; CHECK: %cond = icmp
20 ; CHECK: br i1 %cond
21 ; Comparing two pointers
22 br i1 %cond, label %taken, label %untaken
23
24 taken: ; preds = %continue
25 ret i1 true
26
27 untaken: ; preds = %continue
28 ret i1 false
29 }
30
31 define i1 @test2(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare) gc "statepoint-example" {
32 ; CHECK-LABEL: @test2
33 entry:
34 %cond = icmp eq i8 addrspace(1)* %p, %q
35 br i1 %rare, label %safepoint, label %continue, !prof !0
36
37 safepoint: ; preds = %entry
38 call void @safepoint() [ "deopt"() ]
39 br label %continue
40
41 continue: ; preds = %safepoint, %entry
42 ; CHECK-LABEL: continue:
43 ; CHECK: phi
44 ; CHECK-DAG: [ %q.relocated, %safepoint ]
45 ; CHECK-DAG: [ %q, %entry ]
46 ; CHECK: phi
47 ; CHECK-DAG: [ %p.relocated, %safepoint ]
48 ; CHECK-DAG: [ %p, %entry ]
49 ; CHECK: %cond = icmp
50 ; CHECK: br i1 %cond
51 ; Sanity check that nothing bad happens if already last instruction
52 ; before terminator
53 br i1 %cond, label %taken, label %untaken
54
55 taken: ; preds = %continue
56 ret i1 true
57
58 untaken: ; preds = %continue
59 ret i1 false
60 }
61
62 define i1 @test3(i8 addrspace(1)* %p, i8 addrspace(1)* %q, i1 %rare) gc "statepoint-example" {
63 ; CHECK-LABEL: @test3
64 ; CHECK: gc.statepoint
65 ; CHECK: %cond = icmp
66 ; CHECK: br i1 %cond
67 entry:
68 call void @safepoint() [ "deopt"() ]
69 %cond = icmp eq i8 addrspace(1)* %p, %q
70 br i1 %cond, label %taken, label %untaken
71
72 taken: ; preds = %entry
73 ret i1 true
74
75 untaken: ; preds = %entry
76 ret i1 false
77 }
78
79 declare void @safepoint()
80 !0 = !{!"branch_weights", i32 1, i32 10000}
+0
-51
test/Transforms/RewriteStatepointsForGC/deopt-bundles/constants.ll less more
None ; RUN: opt -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles < %s | FileCheck %s
1
2 ; constants don't get relocated.
3 @G = addrspace(1) global i8 5
4
5 declare void @foo()
6
7 define i8 @test() gc "statepoint-example" {
8 ; CHECK-LABEL: @test
9 ; CHECK: gc.statepoint
10 ; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
11 ; Mostly just here to show reasonable code test can come from.
12 entry:
13 call void @foo() [ "deopt"() ]
14 %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
15 ret i8 %res
16 }
17
18 define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
19 ; CHECK-LABEL: @test2
20 ; CHECK: gc.statepoint
21 ; CHECK-NEXT: gc.relocate
22 ; CHECK-NEXT: icmp
23 ; Globals don't move and thus don't get relocated
24 entry:
25 call void @foo() [ "deopt"() ]
26 %cmp = icmp eq i8 addrspace(1)* %p, null
27 br i1 %cmp, label %taken, label %not_taken
28
29 taken: ; preds = %not_taken, %entry
30 ret i8 0
31
32 not_taken: ; preds = %entry
33 %cmp2 = icmp ne i8 addrspace(1)* %p, null
34 br i1 %cmp2, label %taken, label %dead
35
36 dead: ; preds = %not_taken
37 %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
38 %res = load i8, i8 addrspace(1)* %addr
39 ret i8 %res
40 }
41
42 define i8 @test3(i1 %always_true) gc "statepoint-example" {
43 ; CHECK-LABEL: @test3
44 ; CHECK: gc.statepoint
45 ; CHECK-NEXT: load i8, i8 addrspace(1)* @G
46 entry:
47 call void @foo() [ "deopt"() ]
48 %res = load i8, i8 addrspace(1)* @G, align 1
49 ret i8 %res
50 }
+0
-104
test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll less more
None ; RUN: opt -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles < %s | FileCheck %s
1
2 ; CHECK: declare i8 addrspace(1)* @some_function_ret_deref()
3 ; CHECK: define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* %a)
4 ; CHECK: define i8 addrspace(1)* @test_deref_or_null_arg(i8 addrspace(1)* %a)
5 ; CHECK: define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* %a)
6
7 declare void @foo()
8
9 declare i8 addrspace(1)* @some_function() "gc-leaf-function"
10
11 declare void @some_function_consumer(i8 addrspace(1)*) "gc-leaf-function"
12
13 declare dereferenceable(4) i8 addrspace(1)* @some_function_ret_deref() "gc-leaf-function"
14 declare noalias i8 addrspace(1)* @some_function_ret_noalias() "gc-leaf-function"
15
16 define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* dereferenceable(4) %a) gc "statepoint-example" {
17 entry:
18 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
19 ret i8 addrspace(1)* %a
20 }
21
22 define i8 addrspace(1)* @test_deref_or_null_arg(i8 addrspace(1)* dereferenceable_or_null(4) %a) gc "statepoint-example" {
23 entry:
24 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
25 ret i8 addrspace(1)* %a
26 }
27
28 define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* noalias %a) gc "statepoint-example" {
29 entry:
30 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
31 ret i8 addrspace(1)* %a
32 }
33
34 define i8 addrspace(1)* @test_deref_retval() gc "statepoint-example" {
35 ; CHECK-LABEL: @test_deref_retval(
36 ; CHECK: %a = call i8 addrspace(1)* @some_function()
37 entry:
38 %a = call dereferenceable(4) i8 addrspace(1)* @some_function()
39 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
40 ret i8 addrspace(1)* %a
41 }
42
43 define i8 addrspace(1)* @test_deref_or_null_retval() gc "statepoint-example" {
44 ; CHECK-LABEL: @test_deref_or_null_retval(
45 ; CHECK: %a = call i8 addrspace(1)* @some_function()
46 entry:
47 %a = call dereferenceable_or_null(4) i8 addrspace(1)* @some_function()
48 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
49 ret i8 addrspace(1)* %a
50 }
51
52 define i8 addrspace(1)* @test_noalias_retval() gc "statepoint-example" {
53 ; CHECK-LABEL: @test_noalias_retval(
54 ; CHECK: %a = call i8 addrspace(1)* @some_function()
55 entry:
56 %a = call noalias i8 addrspace(1)* @some_function()
57 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
58 ret i8 addrspace(1)* %a
59 }
60
61 define i8 @test_md(i8 addrspace(1)* %ptr) gc "statepoint-example" {
62 ; CHECK-LABEL: @test_md(
63 ; CHECK: %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !0
64 entry:
65 %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !0
66 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
67 ret i8 %tmp
68 }
69
70 define i8 addrspace(1)* @test_decl_only_attribute(i8 addrspace(1)* %ptr) gc "statepoint-example" {
71 ; CHECK-LABEL: @test_decl_only_attribute(
72 ; No change here, but the prototype of some_function_ret_deref should have changed.
73 ; CHECK: call i8 addrspace(1)* @some_function_ret_deref()
74 entry:
75 %a = call i8 addrspace(1)* @some_function_ret_deref()
76 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
77 ret i8 addrspace(1)* %a
78 }
79
80 define i8 addrspace(1)* @test_decl_only_noalias(i8 addrspace(1)* %ptr) gc "statepoint-example" {
81 ; CHECK-LABEL: @test_decl_only_noalias(
82 ; No change here, but the prototype of some_function_ret_noalias should have changed.
83 ; CHECK: call i8 addrspace(1)* @some_function_ret_noalias()
84 entry:
85 %a = call i8 addrspace(1)* @some_function_ret_noalias()
86 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
87 ret i8 addrspace(1)* %a
88 }
89
90 define i8 addrspace(1)* @test_callsite_arg_attribute(i8 addrspace(1)* %ptr) gc "statepoint-example" {
91 ; CHECK-LABEL: @test_callsite_arg_attribute(
92 ; CHECK: call void @some_function_consumer(i8 addrspace(1)* %ptr)
93 ; CHECK: !0 = !{!1, !1, i64 0}
94 ; CHECK: !1 = !{!"red", !2}
95 ; CHECK: !2 = !{!"blue"}
96 entry:
97 call void @some_function_consumer(i8 addrspace(1)* dereferenceable(4) noalias %ptr)
98 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
99 ret i8 addrspace(1)* %ptr
100 }
101 !0 = !{!1, !1, i64 0, i64 1}
102 !1 = !{!"red", !2}
103 !2 = !{!"blue"}
+0
-22
test/Transforms/RewriteStatepointsForGC/deopt-bundles/gc-relocate-creation.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S 2>&1 | FileCheck %s
1
2 ; This test is to verify gc.relocate can handle pointer to vector of
3 ; pointers (<2 x i32 addrspace(1)*> addrspace(1)* in this case).
4 ; The old scheme to create a gc.relocate of <2 x i32 addrspace(1)*> addrspace(1)*
5 ; type will fail because llvm does not support mangling vector of pointers.
6 ; The new scheme will create all gc.relocate to i8 addrspace(1)* type and
7 ; then bitcast to the correct type.
8
9 declare void @foo()
10
11 declare void @use(...) "gc-leaf-function"
12
13 define void @test1(<2 x i32 addrspace(1)*> addrspace(1)* %obj) gc "statepoint-example" {
14 entry:
15 ; CHECK: %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 7, i32 7)
16 ; CHECK-NEXT: %obj.relocated.casted = bitcast i8 addrspace(1)* %obj.relocated to <2 x i32 addrspace(1)*> addrspace(1)*
17
18 call void @foo() [ "deopt"() ]
19 call void (...) @use(<2 x i32 addrspace(1)*> addrspace(1)* %obj)
20 ret void
21 }
+0
-111
test/Transforms/RewriteStatepointsForGC/deopt-bundles/invokes.ll less more
None ; RUN: opt < %s -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles | FileCheck %s
1
2 declare i64 addrspace(1)* @some_call(i64 addrspace(1)*)
3 declare i32 @personality_function()
4
5 define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality_function {
6 ; CHECK-LABEL: entry:
7 entry:
8 ; CHECK: invoke
9 ; CHECK: statepoint
10 ; CHECK: some_call
11 %ret_val = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
12 to label %normal_return unwind label %exceptional_return
13
14 ; CHECK-LABEL: normal_return:
15 ; CHECK: gc.result
16 ; CHECK: ret i64
17
18 normal_return:
19 ret i64 addrspace(1)* %ret_val
20
21 ; CHECK-LABEL: exceptional_return:
22 ; CHECK: landingpad
23 ; CHECK: ret i64
24
25 exceptional_return:
26 %landing_pad4 = landingpad token
27 cleanup
28 ret i64 addrspace(1)* %obj1
29 }
30
31 define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality_function {
32 ; CHECK-LABEL: entry:
33 entry:
34 ; CHECK: invoke
35 ; CHECK: statepoint
36 ; CHECK: some_call
37 %ret_val1 = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
38 to label %second_invoke unwind label %exceptional_return
39
40 ; CHECK-LABEL: second_invoke:
41 second_invoke:
42 ; CHECK: invoke
43 ; CHECK: statepoint
44 ; CHECK: some_call
45 %ret_val2 = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %ret_val1)
46 to label %normal_return unwind label %exceptional_return
47
48 ; CHECK-LABEL: normal_return:
49 normal_return:
50 ; CHECK: gc.result
51 ; CHECK: ret i64
52 ret i64 addrspace(1)* %ret_val2
53
54 ; CHECK: exceptional_return:
55 ; CHECK: ret i64
56
57 exceptional_return:
58 %landing_pad4 = landingpad token
59 cleanup
60 ret i64 addrspace(1)* %obj1
61 }
62
63 define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) gc "statepoint-example" personality i32 ()* @personality_function {
64 ; CHECK-LABEL: @test_phi_node
65 ; CHECK-LABEL: entry:
66 entry:
67 br i1 %cond, label %left, label %right
68
69 left:
70 %ret_val_left = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
71 to label %merge unwind label %exceptional_return
72
73 right:
74 %ret_val_right = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
75 to label %merge unwind label %exceptional_return
76
77 ; CHECK: merge[[A:[0-9]]]:
78 ; CHECK: gc.result
79 ; CHECK: br label %[[with_phi:merge[0-9]*]]
80
81 ; CHECK: merge[[B:[0-9]]]:
82 ; CHECK: gc.result
83 ; CHECK: br label %[[with_phi]]
84
85 ; CHECK: [[with_phi]]:
86 ; CHECK: phi
87 ; CHECK: ret i64 addrspace(1)* %ret_val
88 merge:
89 %ret_val = phi i64 addrspace(1)* [%ret_val_left, %left], [%ret_val_right, %right]
90 ret i64 addrspace(1)* %ret_val
91
92 ; CHECK-LABEL: exceptional_return:
93 ; CHECK: ret i64 addrspace(1)*
94
95 exceptional_return:
96 %landing_pad4 = landingpad token
97 cleanup
98 ret i64 addrspace(1)* %obj
99 }
100
101 declare void @do_safepoint()
102 define void @gc.safepoint_poll() {
103 ; CHECK-LABEL: gc.safepoint_poll
104 ; CHECK-LABEL: entry
105 ; CHECK-NEXT: do_safepoint
106 ; CHECK-NEXT: ret void
107 entry:
108 call void @do_safepoint()
109 ret void
110 }
+0
-33
test/Transforms/RewriteStatepointsForGC/deopt-bundles/leaf-function.ll less more
None ; RUN: opt < %s -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles | FileCheck %s
1
2 declare void @foo() "gc-leaf-function"
3 declare void @bar()
4
5 ; Calls of functions with the "gc-leaf-function" attribute shouldn't be turned
6 ; into a safepoint. An entry safepoint should get inserted, though.
7 define void @test_leaf_function() gc "statepoint-example" {
8 ; CHECK-LABEL: test_leaf_function
9 ; CHECK-NOT: gc.statepoint
10 ; CHECK-NOT: gc.result
11 entry:
12 call void @foo()
13 ret void
14 }
15
16 define void @test_leaf_function_call() gc "statepoint-example" {
17 ; CHECK-LABEL: test_leaf_function_call
18 ; CHECK-NOT: gc.statepoint
19 ; CHECK-NOT: gc.result
20 entry:
21 call void @bar() "gc-leaf-function"
22 ret void
23 }
24
25 ; This function is inlined when inserting a poll.
26 declare void @do_safepoint()
27 define void @gc.safepoint_poll() {
28 ; CHECK-LABEL: gc.safepoint_poll
29 entry:
30 call void @do_safepoint()
31 ret void
32 }
+0
-112
test/Transforms/RewriteStatepointsForGC/deopt-bundles/live-vector-nosplit.ll less more
None ; Test that we can correctly handle vectors of pointers in statepoint
1 ; rewriting.
2 ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -rs4gc-split-vector-values=0 -S | FileCheck %s
3
4 ; A non-vector relocation for comparison
5 define i64 addrspace(1)* @test(i64 addrspace(1)* %obj) gc "statepoint-example" {
6 ; CHECK-LABEL: test
7 ; CHECK: gc.statepoint
8 ; CHECK-NEXT: gc.relocate
9 ; CHECK-NEXT: bitcast
10 ; CHECK-NEXT: ret i64 addrspace(1)*
11 ; A base vector from a argument
12 entry:
13 call void @do_safepoint() [ "deopt"() ]
14 ret i64 addrspace(1)* %obj
15 }
16
17 ; A vector argument
18 define <2 x i64 addrspace(1)*> @test2(<2 x i64 addrspace(1)*> %obj) gc "statepoint-example" {
19 ; CHECK-LABEL: test2
20 ; CHECK-NEXT: gc.statepoint
21 ; CHECK-NEXT: gc.relocate
22 ; CHECK-NEXT: bitcast
23 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
24 call void @do_safepoint() [ "deopt"() ]
25 ret <2 x i64 addrspace(1)*> %obj
26 }
27
28 ; A load
29 define <2 x i64 addrspace(1)*> @test3(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
30 ; CHECK-LABEL: test3
31 ; CHECK: load
32 ; CHECK-NEXT: gc.statepoint
33 ; CHECK-NEXT: gc.relocate
34 ; CHECK-NEXT: bitcast
35 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
36 entry:
37 %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
38 call void @do_safepoint() [ "deopt"() ]
39 ret <2 x i64 addrspace(1)*> %obj
40 }
41
42 declare i32 @fake_personality_function()
43
44 ; When a statepoint is an invoke rather than a call
45 define <2 x i64 addrspace(1)*> @test4(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" personality i32 ()* @fake_personality_function {
46 ; CHECK-LABEL: test4
47 ; CHECK: load
48 ; CHECK-NEXT: gc.statepoint
49 entry:
50 %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
51 invoke void @do_safepoint() [ "deopt"() ]
52 to label %normal_return unwind label %exceptional_return
53
54 normal_return: ; preds = %entry
55 ; CHECK-LABEL: normal_return:
56 ; CHECK: gc.relocate
57 ; CHECK-NEXT: bitcast
58 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
59 ret <2 x i64 addrspace(1)*> %obj
60
61 exceptional_return: ; preds = %entry
62 ; CHECK-LABEL: exceptional_return:
63 ; CHECK: gc.relocate
64 ; CHECK-NEXT: bitcast
65 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
66 %landing_pad4 = landingpad token
67 cleanup
68 ret <2 x i64 addrspace(1)*> %obj
69 }
70
71 ; A newly created vector
72 define <2 x i64 addrspace(1)*> @test5(i64 addrspace(1)* %p) gc "statepoint-example" {
73 ; CHECK-LABEL: test5
74 ; CHECK: insertelement
75 ; CHECK-NEXT: gc.statepoint
76 ; CHECK-NEXT: gc.relocate
77 ; CHECK-NEXT: bitcast
78 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %vec.relocated.casted
79 entry:
80 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %p, i32 0
81 call void @do_safepoint() [ "deopt"() ]
82 ret <2 x i64 addrspace(1)*> %vec
83 }
84
85 ; A merge point
86 define <2 x i64 addrspace(1)*> @test6(i1 %cnd, <2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
87 ; CHECK-LABEL: test6
88 entry:
89 br i1 %cnd, label %taken, label %untaken
90
91 taken: ; preds = %entry
92 %obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
93 br label %merge
94
95 untaken: ; preds = %entry
96 %objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
97 br label %merge
98
99 merge: ; preds = %untaken, %taken
100 ; CHECK-LABEL: merge:
101 ; CHECK-NEXT: = phi
102 ; CHECK-NEXT: gc.statepoint
103 ; CHECK-NEXT: gc.relocate
104 ; CHECK-NEXT: bitcast
105 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
106 %obj = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ]
107 call void @do_safepoint() [ "deopt"() ]
108 ret <2 x i64 addrspace(1)*> %obj
109 }
110
111 declare void @do_safepoint()
+0
-149
test/Transforms/RewriteStatepointsForGC/deopt-bundles/live-vector.ll less more
None ; Test that we can correctly handle vectors of pointers in statepoint
1 ; rewriting. Currently, we scalarize, but that's an implementation detail.
2 ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -rs4gc-split-vector-values -S | FileCheck %s
3
4 ; A non-vector relocation for comparison
5
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %obj) gc "statepoint-example" {
7 ; CHECK-LABEL: test
8 ; CHECK: gc.statepoint
9 ; CHECK-NEXT: gc.relocate
10 ; CHECK-NEXT: bitcast
11 ; CHECK-NEXT: ret i64 addrspace(1)* %obj.relocated.casted
12 ; A base vector from a argument
13 entry:
14 call void @do_safepoint() [ "deopt"() ]
15 ret i64 addrspace(1)* %obj
16 }
17
18 define <2 x i64 addrspace(1)*> @test2(<2 x i64 addrspace(1)*> %obj) gc "statepoint-example" {
19 ; CHECK-LABEL: test2
20 ; CHECK: extractelement
21 ; CHECK-NEXT: extractelement
22 ; CHECK-NEXT: gc.statepoint
23 ; CHECK-NEXT: gc.relocate
24 ; CHECK-NEXT: bitcast
25 ; CHECK-NEXT: gc.relocate
26 ; CHECK-NEXT: bitcast
27 ; CHECK-NEXT: insertelement
28 ; CHECK-NEXT: insertelement
29 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
30 ; A base vector from a load
31 entry:
32 call void @do_safepoint() [ "deopt"() ]
33 ret <2 x i64 addrspace(1)*> %obj
34 }
35
36 define <2 x i64 addrspace(1)*> @test3(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
37 ; CHECK-LABEL: test3
38 ; CHECK: load
39 ; CHECK-NEXT: extractelement
40 ; CHECK-NEXT: extractelement
41 ; CHECK-NEXT: gc.statepoint
42 ; CHECK-NEXT: gc.relocate
43 ; CHECK-NEXT: bitcast
44 ; CHECK-NEXT: gc.relocate
45 ; CHECK-NEXT: bitcast
46 ; CHECK-NEXT: insertelement
47 ; CHECK-NEXT: insertelement
48 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
49 ; When a statepoint is an invoke rather than a call
50 entry:
51 %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
52 call void @do_safepoint() [ "deopt"() ]
53 ret <2 x i64 addrspace(1)*> %obj
54 }
55
56 declare i32 @fake_personality_function()
57
58 define <2 x i64 addrspace(1)*> @test4(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" personality i32 ()* @fake_personality_function {
59 ; CHECK-LABEL: test4
60 ; CHECK: load
61 ; CHECK-NEXT: extractelement
62 ; CHECK-NEXT: extractelement
63 ; CHECK-NEXT: gc.statepoint
64 entry:
65 %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
66 invoke void @do_safepoint() [ "deopt"() ]
67 to label %normal_return unwind label %exceptional_return
68
69 normal_return: ; preds = %entry
70 ; CHECK-LABEL: normal_return:
71 ; CHECK: gc.relocate
72 ; CHECK-NEXT: bitcast
73 ; CHECK-NEXT: gc.relocate
74 ; CHECK-NEXT: bitcast
75 ; CHECK-NEXT: insertelement
76 ; CHECK-NEXT: insertelement
77 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
78 ret <2 x i64 addrspace(1)*> %obj
79
80 exceptional_return: ; preds = %entry
81 ; CHECK-LABEL: exceptional_return:
82 ; CHECK: gc.relocate
83 ; CHECK-NEXT: bitcast
84 ; CHECK-NEXT: gc.relocate
85 ; CHECK-NEXT: bitcast
86 ; CHECK-NEXT: insertelement
87 ; CHECK-NEXT: insertelement
88 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %13
89 ; Can we handle an insert element with a constant offset? This effectively
90 ; tests both the equal and inequal case since we have to relocate both indices
91 ; in the vector.
92 %landing_pad4 = landingpad token
93 cleanup
94 ret <2 x i64 addrspace(1)*> %obj
95 }
96
97 define <2 x i64 addrspace(1)*> @test5(i64 addrspace(1)* %p) gc "statepoint-example" {
98 ; CHECK-LABEL: test5
99 ; CHECK: insertelement
100 ; CHECK-NEXT: extractelement
101 ; CHECK-NEXT: extractelement
102 ; CHECK-NEXT: gc.statepoint
103 ; CHECK-NEXT: gc.relocate
104 ; CHECK-NEXT: bitcast
105 ; CHECK-NEXT: gc.relocate
106 ; CHECK-NEXT: bitcast
107 ; CHECK-NEXT: insertelement
108 ; CHECK-NEXT: insertelement
109 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
110 ; A base vector from a load
111 entry:
112 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %p, i32 0
113 call void @do_safepoint() [ "deopt"() ]
114 ret <2 x i64 addrspace(1)*> %vec
115 }
116
117 define <2 x i64 addrspace(1)*> @test6(i1 %cnd, <2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
118 ; CHECK-LABEL: test6
119 entry:
120 br i1 %cnd, label %taken, label %untaken
121
122 taken: ; preds = %entry
123 %obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
124 br label %merge
125
126 untaken: ; preds = %entry
127 %objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
128 br label %merge
129
130 merge: ; preds = %untaken, %taken
131 ; CHECK-LABEL: merge:
132 ; CHECK-NEXT: = phi
133 ; CHECK-NEXT: extractelement
134 ; CHECK-NEXT: extractelement
135 ; CHECK-NEXT: gc.statepoint
136 ; CHECK-NEXT: gc.relocate
137 ; CHECK-NEXT: bitcast
138 ; CHECK-NEXT: gc.relocate
139 ; CHECK-NEXT: bitcast
140 ; CHECK-NEXT: insertelement
141 ; CHECK-NEXT: insertelement
142 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*>
143 %obj = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ]
144 call void @do_safepoint() [ "deopt"() ]
145 ret <2 x i64 addrspace(1)*> %obj
146 }
147
148 declare void @do_safepoint()
+0
-165
test/Transforms/RewriteStatepointsForGC/deopt-bundles/liveness-basics.ll less more
None ; A collection of liveness test cases to ensure we're reporting the
1 ; correct live values at statepoints
2 ; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-rematerialization-threshold=0 -S < %s | FileCheck %s
3
4 ; Tests to make sure we consider %obj live in both the taken and untaken
5 ; predeccessor of merge.
6
7 define i64 addrspace(1)* @test1(i1 %cmp, i64 addrspace(1)* %obj) gc "statepoint-example" {
8 ; CHECK-LABEL: @test1
9 entry:
10 br i1 %cmp, label %taken, label %untaken
11
12 taken: ; preds = %entry
13 ; CHECK-LABEL: taken:
14 ; CHECK-NEXT: gc.statepoint
15 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
16 ; CHECK-NEXT: bitcast
17 ; CHECK-NEXT: br label %merge
18 call void @foo() [ "deopt"() ]
19 br label %merge
20
21 untaken: ; preds = %entry
22 ; CHECK-LABEL: untaken:
23 ; CHECK-NEXT: gc.statepoint
24 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
25 ; CHECK-NEXT: bitcast
26 ; CHECK-NEXT: br label %merge
27 call void @foo() [ "deopt"() ]
28 br label %merge
29
30 merge: ; preds = %untaken, %taken
31 ; CHECK-LABEL: merge:
32 ; CHECK-NEXT: %.0 = phi i64 addrspace(1)* [ %obj.relocated.casted, %taken ], [ %obj.relocated2.casted, %untaken ]
33 ; CHECK-NEXT: ret i64 addrspace(1)* %.0
34 ; A local kill should not effect liveness in predecessor block
35 ret i64 addrspace(1)* %obj
36 }
37
38 define i64 addrspace(1)* @test2(i1 %cmp, i64 addrspace(1)** %loc) gc "statepoint-example" {
39 ; CHECK-LABEL: @test2
40 entry:
41 ; CHECK-LABEL: entry:
42 ; CHECK-NEXT: gc.statepoint
43 ; CHECK-NEXT: br
44 call void @foo() [ "deopt"() ]
45 br i1 %cmp, label %taken, label %untaken
46
47 taken: ; preds = %entry
48 ; CHECK-LABEL: taken:
49 ; CHECK-NEXT: %obj = load
50 ; CHECK-NEXT: gc.statepoint
51 ; CHECK-NEXT: gc.relocate
52 ; CHECK-NEXT: bitcast
53 ; CHECK-NEXT: ret i64 addrspace(1)* %obj.relocated.casted
54 ; A local kill should effect values live from a successor phi. Also, we
55 ; should only propagate liveness from a phi to the appropriate predecessors.
56 %obj = load i64 addrspace(1)*, i64 addrspace(1)** %loc
57 call void @foo() [ "deopt"() ]
58 ret i64 addrspace(1)* %obj
59
60 untaken: ; preds = %entry
61 ret i64 addrspace(1)* null
62 }
63
64 define i64 addrspace(1)* @test3(i1 %cmp, i64 addrspace(1)** %loc) gc "statepoint-example" {
65 ; CHECK-LABEL: @test3
66 entry:
67 br i1 %cmp, label %taken, label %untaken
68
69 taken: ; preds = %entry
70 ; CHECK-LABEL: taken:
71 ; CHECK-NEXT: gc.statepoint
72 ; CHECK-NEXT: %obj = load
73 ; CHECK-NEXT: gc.statepoint
74 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
75 ; CHECK-NEXT: bitcast
76 ; CHECK-NEXT: br label %merge
77 call void @foo() [ "deopt"() ]
78 %obj = load i64 addrspace(1)*, i64 addrspace(1)** %loc
79 call void @foo() [ "deopt"() ]
80 br label %merge
81
82 untaken: ; preds = %entry
83 ; CHECK-LABEL: taken:
84 ; CHECK-NEXT: gc.statepoint
85 ; CHECK-NEXT: br label %merge
86 ; A base pointer must be live if it is needed at a later statepoint,
87 ; even if the base pointer is otherwise unused.
88 call void @foo() [ "deopt"() ]
89 br label %merge
90
91 merge: ; preds = %untaken, %taken
92 %phi = phi i64 addrspace(1)* [ %obj, %taken ], [ null, %untaken ]
93 ret i64 addrspace(1)* %phi
94 }
95
96 define i64 addrspace(1)* @test4(i1 %cmp, i64 addrspace(1)* %obj) gc "statepoint-example" {
97 ; CHECK-LABEL: @test4
98 entry:
99 ; CHECK-LABEL: entry:
100 ; CHECK-NEXT: %derived = getelementptr
101 ; CHECK-NEXT: gc.statepoint
102 ; CHECK-NEXT: %derived.relocated =
103 ; CHECK-NEXT: bitcast
104 ; CHECK-NEXT: %obj.relocated =
105 ; CHECK-NEXT: bitcast
106 ; CHECK-NEXT: gc.statepoint
107 ; CHECK-NEXT: %derived.relocated2 =
108 ; CHECK-NEXT: bitcast
109
110 ; Note: It's legal to relocate obj again, but not strictly needed
111 ; CHECK-NEXT: %obj.relocated3 =
112 ; CHECK-NEXT: bitcast
113 ; CHECK-NEXT: ret i64 addrspace(1)* %derived.relocated2.casted
114 ;
115 ; Make sure that a phi def visited during iteration is considered a kill.
116 ; Also, liveness after base pointer analysis can change based on new uses,
117 ; not just new defs.
118 %derived = getelementptr i64, i64 addrspace(1)* %obj, i64 8
119 call void @foo() [ "deopt"() ]
120 call void @foo() [ "deopt"() ]
121 ret i64 addrspace(1)* %derived
122 }
123
124 declare void @consume(...) readonly "gc-leaf-function"
125
126 define i64 addrspace(1)* @test5(i1 %cmp, i64 addrspace(1)* %obj) gc "statepoint-example" {
127 ; CHECK-LABEL: @test5
128 entry:
129 br i1 %cmp, label %taken, label %untaken
130
131 taken: ; preds = %entry
132 ; CHECK-LABEL: taken:
133 ; CHECK-NEXT: gc.statepoint
134 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
135 ; CHECK-NEXT: bitcast
136 ; CHECK-NEXT: br label %merge
137 call void @foo() [ "deopt"() ]
138 br label %merge
139
140 untaken: ; preds = %entry
141 ; CHECK-LABEL: untaken:
142 ; CHECK-NEXT: br label %merge
143 br label %merge
144
145 merge: ; preds = %untaken, %taken
146 ; CHECK-LABEL: merge:
147 ; CHECK-NEXT: %.0 = phi i64 addrspace(1)*
148 ; CHECK-NEXT: %obj2a = phi
149 ; CHECK-NEXT: @consume
150 ; CHECK-NEXT: br label %final
151 %obj2a = phi i64 addrspace(1)* [ %obj, %taken ], [ null, %untaken ]
152 call void (...) @consume(i64 addrspace(1)* %obj2a)
153 br label %final
154
155 final: ; preds = %merge
156 ; CHECK-LABEL: final:
157 ; CHECK-NEXT: @consume
158 ; CHECK-NEXT: ret i64 addrspace(1)* %.0
159 call void (...) @consume(i64 addrspace(1)* %obj2a)
160 ret i64 addrspace(1)* %obj
161 }
162
163 declare void @foo()
164
+0
-44
test/Transforms/RewriteStatepointsForGC/deopt-bundles/patchable-statepoints.ll less more
None ; RUN: opt -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles < %s | FileCheck %s
1
2 declare void @f()
3 declare i32 @personality_function()
4
5 define void @test_id() gc "statepoint-example" personality i32 ()* @personality_function {
6 ; CHECK-LABEL: @test_id(
7 entry:
8 ; CHECK-LABEL: entry:
9 ; CHECK: invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 100, i32 0, void ()* @f
10 invoke void @f() "statepoint-id"="100" to label %normal_return unwind label %exceptional_return
11
12 normal_return:
13 ret void
14
15 exceptional_return:
16 %landing_pad4 = landingpad {i8*, i32} cleanup
17 ret void
18 }
19
20 define void @test_num_patch_bytes() gc "statepoint-example" personality i32 ()* @personality_function {
21 ; CHECK-LABEL: @test_num_patch_bytes(
22 entry:
23 ; CHECK-LABEL: entry:
24 ; CHECK: invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 99, void ()* @f,
25 invoke void @f() "statepoint-num-patch-bytes"="99" to label %normal_return unwind label %exceptional_return
26
27 normal_return:
28 ret void
29
30 exceptional_return:
31 %landing_pad4 = landingpad {i8*, i32} cleanup
32 ret void
33 }
34
35 declare void @do_safepoint()
36 define void @gc.safepoint_poll() {
37 entry:
38 call void @do_safepoint()
39 ret void
40 }
41
42 ; CHECK-NOT: statepoint-id
43 ; CHECK-NOT: statepoint-num-patch_bytes
+0
-62
test/Transforms/RewriteStatepointsForGC/deopt-bundles/preprocess.ll less more
None ; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S < %s | FileCheck %s
1
2 ; Test to make sure we destroy LCSSA's single entry phi nodes before
3 ; running liveness
4
5 declare void @consume(...) "gc-leaf-function"
6
7 define void @test6(i64 addrspace(1)* %obj) gc "statepoint-example" {
8 ; CHECK-LABEL: @test6
9 entry:
10 br label %next
11
12 next: ; preds = %entry
13 ; CHECK-LABEL: next:
14 ; CHECK-NEXT: gc.statepoint
15 ; CHECK-NEXT: gc.relocate
16 ; CHECK-NEXT: bitcast
17 ; CHECK-NEXT: @consume(i64 addrspace(1)* %obj.relocated.casted)
18 ; CHECK-NEXT: @consume(i64 addrspace(1)* %obj.relocated.casted)
19 ; Need to delete unreachable gc.statepoint call
20 %obj2 = phi i64 addrspace(1)* [ %obj, %entry ]
21 call void @foo() [ "deopt"() ]
22 call void (...) @consume(i64 addrspace(1)* %obj2)
23 call void (...) @consume(i64 addrspace(1)* %obj)
24 ret void
25 }
26
27 define void @test7() gc "statepoint-example" {
28 ; CHECK-LABEL: test7
29 ; CHECK-NOT: gc.statepoint
30 ; Need to delete unreachable gc.statepoint invoke - tested seperately given
31 ; a correct implementation could only remove the instructions, not the block
32 ret void
33
34 unreached: ; preds = %unreached
35 %obj = phi i64 addrspace(1)* [ null, %unreached ]
36 call void @foo() [ "deopt"() ]
37 call void (...) @consume(i64 addrspace(1)* %obj)
38 br label %unreached
39 }
40
41 define void @test8() gc "statepoint-example" personality i32 ()* undef {
42 ; CHECK-LABEL: test8
43 ; CHECK-NOT: gc.statepoint
44 ; Bound the last check-not
45 ret void
46
47 unreached: ; No predecessors!
48 invoke void @foo() [ "deopt"() ]
49 ; CHECK-LABEL: @foo
50 to label %normal_return unwind label %exceptional_return
51
52 normal_return: ; preds = %unreached
53 ret void
54
55 exceptional_return: ; preds = %unreached
56 %landing_pad4 = landingpad { i8*, i32 }
57 cleanup
58 ret void
59 }
60
61 declare void @foo()
+0
-32
test/Transforms/RewriteStatepointsForGC/deopt-bundles/relocate-invoke-result.ll less more
None
1 ;; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -verify -S < %s | FileCheck %s
2 ;; This test is to verify that RewriteStatepointsForGC correctly relocates values
3 ;; defined by invoke instruction results.
4
5 declare i64* addrspace(1)* @non_gc_call() "gc-leaf-function"
6
7 declare void @gc_call()
8
9 declare i32* @fake_personality_function()
10
11 define i64* addrspace(1)* @test() gc "statepoint-example" personality i32* ()* @fake_personality_function {
12 ; CHECK-LABEL: @test(
13
14 entry:
15 %obj = invoke i64* addrspace(1)* @non_gc_call()
16 to label %normal_dest unwind label %unwind_dest
17
18 unwind_dest: ; preds = %entry
19 %lpad = landingpad { i8*, i32 }
20 cleanup
21 resume { i8*, i32 } undef
22
23 normal_dest: ; preds = %entry
24 ; CHECK: normal_dest:
25 ; CHECK-NEXT: gc.statepoint
26 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
27 ; CHECK-NEXT: bitcast
28
29 call void @gc_call() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
30 ret i64* addrspace(1)* %obj
31 }
+0
-279
test/Transforms/RewriteStatepointsForGC/deopt-bundles/relocation.ll less more
None ; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-rematerialization-threshold=0 -S 2>&1 | FileCheck %s
1
2
3 declare void @foo()
4
5 declare void @use(...) "gc-leaf-function"
6
7 define i64 addrspace(1)* @test1(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
8 ; CHECK-LABEL: @test1
9 ; CHECK-DAG: %obj.relocated
10 ; CHECK-DAG: %obj2.relocated
11 entry:
12 call void @foo() [ "deopt"() ]
13 br label %joint
14
15 joint: ; preds = %joint2, %entry
16 ; CHECK-LABEL: joint:
17 ; CHECK: %phi1 = phi i64 addrspace(1)* [ %obj.relocated.casted, %entry ], [ %obj3, %joint2 ]
18 %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj3, %joint2 ]
19 br i1 %condition, label %use, label %joint2
20
21 use: ; preds = %joint
22 br label %joint2
23
24 joint2: ; preds = %use, %joint
25 ; CHECK-LABEL: joint2:
26 ; CHECK: %phi2 = phi i64 addrspace(1)* [ %obj.relocated.casted, %use ], [ %obj2.relocated.casted, %joint ]
27 ; CHECK: %obj3 = getelementptr i64, i64 addrspace(1)* %obj2.relocated.casted, i32 1
28 %phi2 = phi i64 addrspace(1)* [ %obj, %use ], [ %obj2, %joint ]
29 %obj3 = getelementptr i64, i64 addrspace(1)* %obj2, i32 1
30 br label %joint
31 }
32
33 declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
34
35 declare void @consume_obj(i64 addrspace(1)*) "gc-leaf-function"
36
37 declare i1 @rt() "gc-leaf-function"
38
39 define void @test2() gc "statepoint-example" {
40 ; CHECK-LABEL: @test2
41 entry:
42 %obj_init = call i64 addrspace(1)* @generate_obj()
43 %obj = getelementptr i64, i64 addrspace(1)* %obj_init, i32 42
44 br label %loop
45
46 loop: ; preds = %loop.backedge, %entry
47 ; CHECK: loop:
48 ; CHECK-DAG: [ %obj_init.relocated.casted, %loop.backedge ]
49 ; CHECK-DAG: [ %obj_init, %entry ]
50 ; CHECK-DAG: [ %obj.relocated.casted, %loop.backedge ]
51 ; CHECK-DAG: [ %obj, %entry ]
52 ; CHECK-NOT: %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
53 %index = phi i32 [ 0, %entry ], [ %index.inc, %loop.backedge ]
54 %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
55 call void @consume_obj(i64 addrspace(1)* %location)
56 %index.inc = add i32 %index, 1
57 %condition = call i1 @rt()
58 br i1 %condition, label %loop_x, label %loop_y
59
60 loop_x: ; preds = %loop
61 br label %loop.backedge
62
63 loop.backedge: ; preds = %loop_y, %loop_x
64 call void @do_safepoint() [ "deopt"() ]
65 br label %loop
66
67 loop_y: ; preds = %loop
68 br label %loop.backedge
69 }
70
71 declare void @some_call(i8 addrspace(1)*) "gc-leaf-function"
72
73 define void @relocate_merge(i1 %cnd, i8 addrspace(1)* %arg) gc "statepoint-example" {
74 ; CHECK-LABEL: @relocate_merge
75
76 bci_0:
77 br i1 %cnd, label %if_branch, label %else_branch
78
79 if_branch: ; preds = %bci_0
80 ; CHECK-LABEL: if_branch:
81 ; CHECK: gc.statepoint
82 ; CHECK: gc.relocate
83 call void @foo() [ "deopt"() ]
84 br label %join
85
86 else_branch: ; preds = %bci_0
87 ; CHECK-LABEL: else_branch:
88 ; CHECK: gc.statepoint
89 ; CHECK: gc.relocate
90 ; We need to end up with a single relocation phi updated from both paths
91 call void @foo() [ "deopt"() ]
92 br label %join
93
94 join: ; preds = %else_branch, %if_branch
95 ; CHECK-LABEL: join:
96 ; CHECK: phi i8 addrspace(1)*
97 ; CHECK-DAG: [ %arg.relocated, %if_branch ]
98 ; CHECK-DAG: [ %arg.relocated2, %else_branch ]
99 ; CHECK-NOT: phi
100 call void @some_call(i8 addrspace(1)* %arg)
101 ret void
102 }
103
104 ; Make sure a use in a statepoint gets properly relocated at a previous one.
105 ; This is basically just making sure that statepoints aren't accidentally
106 ; treated specially.
107 define void @test3(i64 addrspace(1)* %obj) gc "statepoint-example" {
108 ; CHECK-LABEL: @test3
109 ; CHECK: gc.statepoint
110 ; CHECK-NEXT: gc.relocate
111 ; CHECK-NEXT: bitcast
112 ; CHECK-NEXT: gc.statepoint
113 entry:
114 call void undef(i64 undef) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
115 %0 = call i32 undef(i64 addrspace(1)* %obj) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
116 ret void
117 }
118
119 ; Check specifically for the case where the result of a statepoint needs to
120 ; be relocated itself
121 define void @test4() gc "statepoint-example" {
122 ; CHECK-LABEL: @test4
123 ; CHECK: gc.statepoint
124 ; CHECK: gc.result
125 ; CHECK: gc.statepoint
126 ; CHECK: [[RELOCATED:%[^ ]+]] = call {{.*}}gc.relocate
127 ; CHECK: @use(i8 addrspace(1)* [[RELOCATED]])
128 %1 = call i8 addrspace(1)* undef() [ "deopt"() ]
129 %2 = call i8 addrspace(1)* undef() [ "deopt"() ]
130 call void (...) @use(i8 addrspace(1)* %1)
131 unreachable
132 }
133
134 ; Test updating a phi where not all inputs are live to begin with
135 define void @test5(i8 addrspace(1)* %arg) gc "statepoint-example" {
136 ; CHECK-LABEL: test5
137 entry:
138 %0 = call i8 addrspace(1)* undef() [ "deopt"() ]
139 switch i32 undef, label %kill [
140 i32 10, label %merge
141 i32 13, label %merge
142 ]
143
144 kill: ; preds = %entry
145 br label %merge
146
147 merge: ; preds = %kill, %entry, %entry
148 ; CHECK: merge:
149 ; CHECK: %test = phi i8 addrspace(1)
150 ; CHECK-DAG: [ null, %kill ]
151 ; CHECK-DAG: [ %arg.relocated, %entry ]
152 ; CHECK-DAG: [ %arg.relocated, %entry ]
153 %test = phi i8 addrspace(1)* [ null, %kill ], [ %arg, %entry ], [ %arg, %entry ]
154 call void (...) @use(i8 addrspace(1)* %test)
155 unreachable
156 }
157
158 ; Check to make sure we handle values live over an entry statepoint
159 define void @test6(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) gc "statepoint-example" {
160 ; CHECK-LABEL: @test6
161 entry:
162 br i1 undef, label %gc.safepoint_poll.exit2, label %do_safepoint
163
164 do_safepoint: ; preds = %entry
165 ; CHECK-LABEL: do_safepoint:
166 ; CHECK: gc.statepoint
167 ; CHECK: arg1.relocated =
168 ; CHECK: arg2.relocated =
169 ; CHECK: arg3.relocated =
170 call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) ]
171 br label %gc.safepoint_poll.exit2
172
173 gc.safepoint_poll.exit2: ; preds = %do_safepoint, %entry
174 ; CHECK-LABEL: gc.safepoint_poll.exit2:
175 ; CHECK: phi i8 addrspace(1)*
176 ; CHECK-DAG: [ %arg3, %entry ]
177 ; CHECK-DAG: [ %arg3.relocated, %do_safepoint ]
178 ; CHECK: phi i8 addrspace(1)*
179 ; CHECK-DAG: [ %arg2, %entry ]
180