1 ; RUN: opt < %s -rewrite-statepoints-for-gc -S | FileCheck %s 2 3 4 define i64 addrspace(1)* @test(<2 x i64 addrspace(1)*> %vec, i32 %idx) gc "statepoint-example" { 5 ; CHECK-LABEL: @test 6 ; CHECK: extractelement 7 ; CHECK: extractelement 8 ; CHECK: statepoint 9 ; CHECK: gc.relocate 10 ; CHECK-DAG: ; (%base_ee, %obj) 11 ; CHECK: gc.relocate 12 ; CHECK-DAG: ; (%base_ee, %base_ee) 13 ; Note that the second extractelement is actually redundant here. A correct output would 14 ; be to reuse the existing obj as a base since it is actually a base pointer. 15 entry: 16 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx 17 call void @do_safepoint() [ "deopt"() ] 18 ret i64 addrspace(1)* %obj 19 } 20 21 define i64 addrspace(1)* @test2(<2 x i64 addrspace(1)*>* %ptr, i1 %cnd, i32 %idx1, i32 %idx2) gc "statepoint-example" { 22 ; CHECK-LABEL: test2 23 entry: 24 br i1 %cnd, label %taken, label %untaken 25 26 taken: ; preds = %entry 27 %obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr 28 br label %merge 29 30 untaken: ; preds = %entry 31 %objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr 32 br label %merge 33 34 merge: ; preds = %untaken, %taken 35 %vec = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ] 36 br i1 %cnd, label %taken2, label %untaken2 37 38 taken2: ; preds = %merge 39 %obj0 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx1 40 br label %merge2 41 42 untaken2: ; preds = %merge 43 %obj1 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx2 44 br label %merge2 45 46 merge2: ; preds = %untaken2, %taken2 47 ; CHECK-LABEL: merge2: 48 ; CHECK: %obj.base = phi i64 addrspace(1)* 49 ; CHECK: %obj = phi i64 addrspace(1)* 50 ; CHECK: statepoint 51 ; CHECK: gc.relocate 52 ; CHECK-DAG: ; (%obj.base, %obj) 53 ; CHECK: gc.relocate 54 ; CHECK-DAG: ; (%obj.base, %obj.base) 55 %obj = phi i64 addrspace(1)* [ %obj0, %taken2 ], [ %obj1, %untaken2 ] 56 call void @do_safepoint() [ "deopt"() ] 57 ret i64 addrspace(1)* %obj 58 } 59 60 define i64 addrspace(1)* @test3(i64 addrspace(1)* %ptr) gc "statepoint-example" { 61 ; CHECK-LABEL: test3 62 ; CHECK: insertelement 63 ; CHECK: extractelement 64 ; CHECK: statepoint 65 ; CHECK: gc.relocate 66 ; CHECK-DAG: (%obj.base, %obj) 67 entry: 68 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %ptr, i32 0 69 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0 70 call void @do_safepoint() [ "deopt"() ] 71 ret i64 addrspace(1)* %obj 72 } 73 74 define i64 addrspace(1)* @test4(i64 addrspace(1)* %ptr) gc "statepoint-example" { 75 ; CHECK-LABEL: test4 76 ; CHECK: statepoint 77 ; CHECK: gc.relocate 78 ; CHECK-DAG: ; (%obj.base, %obj) 79 ; When we can optimize an extractelement from a known 80 ; index and avoid introducing new base pointer instructions 81 entry: 82 %derived = getelementptr i64, i64 addrspace(1)* %ptr, i64 16 83 %veca = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %derived, i32 0 84 %vec = insertelement <2 x i64 addrspace(1)*> %veca, i64 addrspace(1)* %ptr, i32 1 85 %obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0 86 call void @do_safepoint() [ "deopt"() ] 87 ret i64 addrspace(1)* %obj 88 } 89 90 declare void @use(i64 addrspace(1)*) "gc-leaf-function" 91 92 define void @test5(i1 %cnd, i64 addrspace(1)* %obj) gc "statepoint-example" { 93 ; CHECK-LABEL: @test5 94 ; CHECK: gc.relocate 95 ; CHECK-DAG: (%bdv.base, %bdv) 96 ; When we fundementally have to duplicate 97 entry: 98 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1 99 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0 100 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i32 0 101 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ] 102 call void @use(i64 addrspace(1)* %bdv) 103 ret void 104 } 105 106 define void @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" { 107 ; CHECK-LABEL: @test6 108 ; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1 109 ; CHECK: %vec.base = insertelement <2 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 0, !is_base_value !0 110 ; CHECK: %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0 111 ; CHECK: %bdv.base = extractelement <2 x i64 addrspace(1)*> %vec.base, i64 %idx, !is_base_value !0 112 ; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx 113 ; CHECK: gc.statepoint 114 ; CHECK: gc.relocate 115 ; CHECK-DAG: (%bdv.base, %bdv) 116 ; A more complicated example involving vector and scalar bases. 117 ; This is derived from a failing test case when we didn't have correct 118 ; insertelement handling. 119 entry: 120 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1 121 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0 122 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx 123 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ] 124 call void @use(i64 addrspace(1)* %bdv) 125 ret void 126 } 127 128 define i64 addrspace(1)* @test7(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" { 129 ; CHECK-LABEL: @test7 130 entry: 131 %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 0 132 br label %merge1 133 134 merge1: ; preds = %merge1, %entry 135 ; CHECK-LABEL: merge1: 136 ; CHECK: vec2.base 137 ; CHECK: vec2 138 ; CHECK: gep 139 ; CHECK: vec3.base 140 ; CHECK: vec3 141 %vec2 = phi <2 x i64 addrspace(1)*> [ %vec, %entry ], [ %vec3, %merge1 ] 142 %gep = getelementptr i64, i64 addrspace(1)* %obj2, i64 1 143 %vec3 = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0 144 br i1 %cnd, label %merge1, label %next1 145 146 next1: ; preds = %merge1 147 ; CHECK-LABEL: next1: 148 ; CHECK: bdv.base = 149 ; CHECK: bdv = 150 %bdv = extractelement <2 x i64 addrspace(1)*> %vec2, i32 0 151 br label %merge 152 153 merge: ; preds = %merge, %next1 154 ; CHECK-LABEL: merge: 155 ; CHECK: %objb.base 156 ; CHECK: %objb 157 ; CHECK: gc.statepoint 158 ; CHECK: gc.relocate 159 ; CHECK-DAG: (%objb.base, %objb) 160 %objb = phi i64 addrspace(1)* [ %obj, %next1 ], [ %bdv, %merge ] 161 br i1 %cnd, label %merge, label %next 162 163 next: ; preds = %merge 164 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ] 165 ret i64 addrspace(1)* %objb 166 } 167 168 declare void @do_safepoint() 169