2016-01-29 08:28:57 +08:00
|
|
|
; RUN: opt < %s -rewrite-statepoints-for-gc -S | FileCheck %s
|
|
|
|
|
2015-08-13 05:00:20 +08:00
|
|
|
|
|
|
|
define i64 addrspace(1)* @test(<2 x i64 addrspace(1)*> %vec, i32 %idx) gc "statepoint-example" {
|
|
|
|
; CHECK-LABEL: @test
|
|
|
|
; CHECK: extractelement
|
|
|
|
; CHECK: extractelement
|
|
|
|
; CHECK: statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: ; (%base_ee, %obj)
|
2016-05-04 22:55:36 +08:00
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: ; (%base_ee, %base_ee)
|
2015-08-13 05:00:20 +08:00
|
|
|
; Note that the second extractelement is actually redundant here. A correct output would
|
|
|
|
; be to reuse the existing obj as a base since it is actually a base pointer.
|
|
|
|
entry:
|
|
|
|
%obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx
|
2016-01-29 08:28:57 +08:00
|
|
|
call void @do_safepoint() [ "deopt"() ]
|
2015-08-13 05:00:20 +08:00
|
|
|
ret i64 addrspace(1)* %obj
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
define i64 addrspace(1)* @test2(<2 x i64 addrspace(1)*>* %ptr, i1 %cnd, i32 %idx1, i32 %idx2) gc "statepoint-example" {
|
2015-08-13 05:00:20 +08:00
|
|
|
; CHECK-LABEL: test2
|
|
|
|
entry:
|
|
|
|
br i1 %cnd, label %taken, label %untaken
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
taken: ; preds = %entry
|
2015-08-13 05:00:20 +08:00
|
|
|
%obja = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
|
|
|
|
br label %merge
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
untaken: ; preds = %entry
|
2015-08-13 05:00:20 +08:00
|
|
|
%objb = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
|
|
|
|
br label %merge
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
merge: ; preds = %untaken, %taken
|
|
|
|
%vec = phi <2 x i64 addrspace(1)*> [ %obja, %taken ], [ %objb, %untaken ]
|
2015-08-13 05:00:20 +08:00
|
|
|
br i1 %cnd, label %taken2, label %untaken2
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
taken2: ; preds = %merge
|
2015-08-13 05:00:20 +08:00
|
|
|
%obj0 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx1
|
|
|
|
br label %merge2
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
untaken2: ; preds = %merge
|
2015-08-13 05:00:20 +08:00
|
|
|
%obj1 = extractelement <2 x i64 addrspace(1)*> %vec, i32 %idx2
|
|
|
|
br label %merge2
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
merge2: ; preds = %untaken2, %taken2
|
2015-08-13 05:00:20 +08:00
|
|
|
; CHECK-LABEL: merge2:
|
2016-02-23 04:45:56 +08:00
|
|
|
; CHECK: %obj.base = phi i64 addrspace(1)*
|
|
|
|
; CHECK: %obj = phi i64 addrspace(1)*
|
|
|
|
; CHECK: statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: ; (%obj.base, %obj)
|
2015-08-13 05:00:20 +08:00
|
|
|
; CHECK: gc.relocate
|
2016-02-23 04:45:56 +08:00
|
|
|
; CHECK-DAG: ; (%obj.base, %obj.base)
|
2016-01-29 08:28:57 +08:00
|
|
|
%obj = phi i64 addrspace(1)* [ %obj0, %taken2 ], [ %obj1, %untaken2 ]
|
|
|
|
call void @do_safepoint() [ "deopt"() ]
|
2015-08-13 05:00:20 +08:00
|
|
|
ret i64 addrspace(1)* %obj
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
define i64 addrspace(1)* @test3(i64 addrspace(1)* %ptr) gc "statepoint-example" {
|
2015-08-13 05:00:20 +08:00
|
|
|
; CHECK-LABEL: test3
|
|
|
|
; CHECK: insertelement
|
|
|
|
; CHECK: extractelement
|
|
|
|
; CHECK: statepoint
|
|
|
|
; CHECK: gc.relocate
|
2016-02-23 04:45:56 +08:00
|
|
|
; CHECK-DAG: (%obj.base, %obj)
|
2016-01-29 08:28:57 +08:00
|
|
|
entry:
|
|
|
|
%vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %ptr, i32 0
|
|
|
|
%obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
|
|
|
|
call void @do_safepoint() [ "deopt"() ]
|
2015-08-13 05:00:20 +08:00
|
|
|
ret i64 addrspace(1)* %obj
|
|
|
|
}
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
define i64 addrspace(1)* @test4(i64 addrspace(1)* %ptr) gc "statepoint-example" {
|
2015-08-13 05:00:20 +08:00
|
|
|
; CHECK-LABEL: test4
|
|
|
|
; CHECK: statepoint
|
|
|
|
; CHECK: gc.relocate
|
2016-02-23 04:45:56 +08:00
|
|
|
; CHECK-DAG: ; (%obj.base, %obj)
|
2016-01-29 08:28:57 +08:00
|
|
|
; When we can optimize an extractelement from a known
|
|
|
|
; index and avoid introducing new base pointer instructions
|
|
|
|
entry:
|
|
|
|
%derived = getelementptr i64, i64 addrspace(1)* %ptr, i64 16
|
|
|
|
%veca = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %derived, i32 0
|
|
|
|
%vec = insertelement <2 x i64 addrspace(1)*> %veca, i64 addrspace(1)* %ptr, i32 1
|
|
|
|
%obj = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
|
|
|
|
call void @do_safepoint() [ "deopt"() ]
|
2015-08-13 05:00:20 +08:00
|
|
|
ret i64 addrspace(1)* %obj
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
declare void @use(i64 addrspace(1)*) "gc-leaf-function"
|
2017-03-17 08:55:53 +08:00
|
|
|
declare void @use_vec(<4 x i64 addrspace(1)*>) "gc-leaf-function"
|
2015-09-10 07:40:12 +08:00
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
define void @test5(i1 %cnd, i64 addrspace(1)* %obj) gc "statepoint-example" {
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: @test5
|
|
|
|
; CHECK: gc.relocate
|
2016-02-23 04:45:56 +08:00
|
|
|
; CHECK-DAG: (%bdv.base, %bdv)
|
2016-01-29 08:28:57 +08:00
|
|
|
; When we fundementally have to duplicate
|
2015-09-10 07:40:12 +08:00
|
|
|
entry:
|
|
|
|
%gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
|
|
|
|
%vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
%bdv = extractelement <2 x i64 addrspace(1)*> %vec, i32 0
|
2016-01-29 08:28:57 +08:00
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
2015-09-10 07:40:12 +08:00
|
|
|
call void @use(i64 addrspace(1)* %bdv)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
define void @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" {
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: @test6
|
|
|
|
; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
|
2016-05-27 21:13:59 +08:00
|
|
|
; CHECK: %vec.base = insertelement <2 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 0, !is_base_value !0
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK: %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
; CHECK: %bdv.base = extractelement <2 x i64 addrspace(1)*> %vec.base, i64 %idx, !is_base_value !0
|
|
|
|
; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
|
|
|
; CHECK: gc.statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: (%bdv.base, %bdv)
|
2016-01-29 08:28:57 +08:00
|
|
|
; A more complicated example involving vector and scalar bases.
|
|
|
|
; This is derived from a failing test case when we didn't have correct
|
|
|
|
; insertelement handling.
|
2015-09-10 07:40:12 +08:00
|
|
|
entry:
|
|
|
|
%gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
|
|
|
|
%vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
%bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
2016-01-29 08:28:57 +08:00
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
2015-09-10 07:40:12 +08:00
|
|
|
call void @use(i64 addrspace(1)* %bdv)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:57 +08:00
|
|
|
define i64 addrspace(1)* @test7(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: @test7
|
|
|
|
entry:
|
|
|
|
%vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 0
|
|
|
|
br label %merge1
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
merge1: ; preds = %merge1, %entry
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: merge1:
|
|
|
|
; CHECK: vec2.base
|
|
|
|
; CHECK: vec2
|
|
|
|
; CHECK: gep
|
|
|
|
; CHECK: vec3.base
|
|
|
|
; CHECK: vec3
|
|
|
|
%vec2 = phi <2 x i64 addrspace(1)*> [ %vec, %entry ], [ %vec3, %merge1 ]
|
|
|
|
%gep = getelementptr i64, i64 addrspace(1)* %obj2, i64 1
|
|
|
|
%vec3 = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
br i1 %cnd, label %merge1, label %next1
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
next1: ; preds = %merge1
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: next1:
|
|
|
|
; CHECK: bdv.base =
|
|
|
|
; CHECK: bdv =
|
|
|
|
%bdv = extractelement <2 x i64 addrspace(1)*> %vec2, i32 0
|
|
|
|
br label %merge
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
merge: ; preds = %merge, %next1
|
2015-09-10 07:40:12 +08:00
|
|
|
; CHECK-LABEL: merge:
|
|
|
|
; CHECK: %objb.base
|
|
|
|
; CHECK: %objb
|
|
|
|
; CHECK: gc.statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: (%objb.base, %objb)
|
|
|
|
%objb = phi i64 addrspace(1)* [ %obj, %next1 ], [ %bdv, %merge ]
|
|
|
|
br i1 %cnd, label %merge, label %next
|
2016-01-29 08:28:57 +08:00
|
|
|
|
|
|
|
next: ; preds = %merge
|
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
2015-09-10 07:40:12 +08:00
|
|
|
ret i64 addrspace(1)* %objb
|
|
|
|
}
|
|
|
|
|
2016-10-04 21:48:37 +08:00
|
|
|
; identify base for shufflevector
|
|
|
|
define void @test8(i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" {
|
|
|
|
; CHECK-LABEL: @test8
|
|
|
|
; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
|
|
|
|
; CHECK: %gep2 = getelementptr i64, i64 addrspace(1)* %obj, i64 2
|
|
|
|
; CHECK: %vec1.base = insertelement <4 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 0, !is_base_value !0
|
|
|
|
; CHECK: %vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
; CHECK: %vec2.base = insertelement <4 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 2, !is_base_value !0
|
|
|
|
; CHECK: %vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep2, i32 2
|
|
|
|
; CHECK: %vec.base = shufflevector <4 x i64 addrspace(1)*> %vec1.base, <4 x i64 addrspace(1)*> %vec2.base, <2 x i32> <i32 0, i32 2>, !is_base_value !0
|
|
|
|
; CHECK: %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec2, <2 x i32> <i32 0, i32 2>
|
|
|
|
; CHECK: %bdv.base = extractelement <2 x i64 addrspace(1)*> %vec.base, i64 %idx, !is_base_value !0
|
|
|
|
; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
|
|
|
; CHECK: gc.statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: (%bdv.base, %bdv)
|
|
|
|
entry:
|
|
|
|
%gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
|
|
|
|
%gep2 = getelementptr i64, i64 addrspace(1)* %obj, i64 2
|
|
|
|
%vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
|
|
|
|
%vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep2, i32 2
|
|
|
|
%vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec2, <2 x i32> <i32 0, i32 2>
|
|
|
|
%bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
|
|
|
call void @use(i64 addrspace(1)* %bdv)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Since the same 'base' vector is used in the shuffle operands, we do not need
|
|
|
|
; create a shufflevector base.
|
|
|
|
define void @test9(<4 x i64 addrspace(1)*> %vec1, i64 %idx) gc "statepoint-example" {
|
|
|
|
; CHECK-LABEL: @test9
|
|
|
|
; CHECK: %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec1, <2 x i32> <i32 0, i32 2>
|
|
|
|
; CHECK: %base_ee = extractelement <4 x i64 addrspace(1)*> %vec1, i64 %idx, !is_base_value !0
|
|
|
|
; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
|
|
|
; CHECK: gc.statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: (%base_ee, %bdv)
|
|
|
|
entry:
|
|
|
|
; shrinking vec1 into vec
|
|
|
|
%vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec1, <2 x i32> <i32 0, i32 2>
|
|
|
|
%bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
|
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
|
|
|
call void @use(i64 addrspace(1)* %bdv)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; vector operand of shufflevector is a phi
|
|
|
|
define i64 addrspace(1)* @test10(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
|
|
|
|
; CHECK-LABEL: @test10
|
|
|
|
entry:
|
|
|
|
%vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj, i32 0
|
|
|
|
br i1 %cnd, label %here, label %merge
|
|
|
|
|
|
|
|
here:
|
|
|
|
%vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 2
|
|
|
|
br label %merge
|
|
|
|
|
|
|
|
merge: ; preds = %merge, %entry, %here
|
|
|
|
; CHECK-LABEL: merge:
|
|
|
|
; CHECK: %vec.base = phi <4 x i64 addrspace(1)*> [ %vec1.base, %entry ], [ %vec2.base, %here ], [ %vec3.base, %merge ], !is_base_value !0
|
|
|
|
; CHECK: vec
|
|
|
|
; CHECK: vec3.base = shufflevector <4 x i64 addrspace(1)*> %vec.base, <4 x i64 addrspace(1)*> %vec.base
|
|
|
|
; CHECK: vec3
|
|
|
|
; CHECK: bdv.base
|
|
|
|
; CHECK: bdv
|
|
|
|
%vec = phi <4 x i64 addrspace(1)*> [ %vec1, %entry ], [ %vec2, %here], [ %vec3, %merge]
|
|
|
|
%vec3 = shufflevector <4 x i64 addrspace(1)*> %vec, <4 x i64 addrspace(1)*> %vec, <4 x i32> <i32 2, i32 0, i32 1, i32 3>
|
|
|
|
%bdv = extractelement <4 x i64 addrspace(1)*> %vec3, i32 0
|
|
|
|
br i1 %cnd, label %merge, label %next
|
|
|
|
|
|
|
|
next:
|
|
|
|
; CHECK-LABEL: next:
|
|
|
|
; CHECK: gc.statepoint
|
|
|
|
; CHECK: gc.relocate
|
|
|
|
; CHECK-DAG: (%bdv.base, %bdv)
|
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
|
|
|
ret i64 addrspace(1)* %bdv
|
|
|
|
}
|
2015-08-13 05:00:20 +08:00
|
|
|
declare void @do_safepoint()
|
2017-03-17 08:55:53 +08:00
|
|
|
|
|
|
|
define void @test11(<4 x i64 addrspace(1)*> %vec1) gc "statepoint-example" {
|
|
|
|
; CHECK-LABEL: @test11(
|
|
|
|
; CHECK: @llvm.experimental.gc.statepoint.p0f_isVoidf{{.*}}<4 x i64 addrspace(1)*> %vec1)
|
|
|
|
; CHECK: %vec1.relocated = call coldcc <4 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v4p1i8
|
|
|
|
; CHECK: %vec1.relocated.casted = bitcast <4 x i8 addrspace(1)*> %vec1.relocated to <4 x i64 addrspace(1)*>
|
|
|
|
; CHECK: %vec2.remat = getelementptr i64, <4 x i64 addrspace(1)*> %vec1.relocated.casted, i32 1024
|
|
|
|
; CHECK: call void @use_vec(<4 x i64 addrspace(1)*> %vec2.remat)
|
|
|
|
entry:
|
|
|
|
%vec2 = getelementptr i64, <4 x i64 addrspace(1)*> %vec1, i32 1024
|
|
|
|
call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
|
|
|
|
call void @use_vec(<4 x i64 addrspace(1) *> %vec2)
|
|
|
|
ret void
|
|
|
|
}
|