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