1; RUN: opt -rewrite-statepoints-for-gc -verify -S < %s | FileCheck %s
2; RUN: opt -passes=rewrite-statepoints-for-gc -verify -S < %s | FileCheck %s
3
4declare i8 addrspace(1)* @gc_call()
5
6declare i32* @fake_personality_function()
7
8define i8 addrspace(1)* @test(i1 %c) gc "statepoint-example" personality i32* ()* @fake_personality_function {
9; CHECK-LABEL: @test(
10entry:
11  br i1 %c, label %gc_invoke, label %normal_dest
12
13gc_invoke:
14; CHECK: [[TOKEN:%[^ ]+]] = invoke token {{[^@]+}}@llvm.experimental.gc.statepoint{{[^@]+}}@gc_call
15  %obj = invoke i8 addrspace(1)* @gc_call() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
16          to label %normal_dest unwind label %unwind_dest
17
18unwind_dest:
19; CHECK: unwind_dest:
20  %lpad = landingpad { i8*, i32 }
21          cleanup
22  resume { i8*, i32 } undef
23
24; CHECK: [[NORMAL_DEST_SPLIT:[^:]+:]]
25; CHECK-NEXT: [[RET_VAL:%[^ ]+]] = call i8 addrspace(1)* @llvm.experimental.gc.result.p1i8(token [[TOKEN]])
26; CHECK-NEXT: br label %normal_dest
27
28normal_dest:
29; CHECK: normal_dest:
30; CHECK-NEXT: %merge = phi i8 addrspace(1)* [ null, %entry ], [ %obj2, %normal_dest1 ]
31  %merge = phi i8 addrspace(1)* [ null, %entry ], [ %obj, %gc_invoke ]
32  ret i8 addrspace(1)* %merge
33}
34