1cee313d2SEric Christopher; RUN: opt -rewrite-statepoints-for-gc -S < %s | FileCheck %s
2cee313d2SEric Christopher; RUN: opt -passes=rewrite-statepoints-for-gc -S < %s | FileCheck %s
3cee313d2SEric Christopher
4cee313d2SEric Christopher; Test to make sure we destroy LCSSA's single entry phi nodes before
5cee313d2SEric Christopher; running liveness
6cee313d2SEric Christopher
7cee313d2SEric Christopherdeclare void @consume(...) "gc-leaf-function"
8cee313d2SEric Christopher
9cee313d2SEric Christopherdefine void @test6(i64 addrspace(1)* %obj) gc "statepoint-example" {
10cee313d2SEric Christopher; CHECK-LABEL: @test6
11cee313d2SEric Christopherentry:
12cee313d2SEric Christopher  br label %next
13cee313d2SEric Christopher
14cee313d2SEric Christophernext:                                             ; preds = %entry
15cee313d2SEric Christopher; CHECK-LABEL: next:
16cee313d2SEric Christopher; CHECK-NEXT: gc.statepoint
17cee313d2SEric Christopher; CHECK-NEXT: gc.relocate
18cee313d2SEric Christopher; CHECK-NEXT: bitcast
19cee313d2SEric Christopher; CHECK-NEXT: @consume(i64 addrspace(1)* %obj.relocated.casted)
20cee313d2SEric Christopher; CHECK-NEXT: @consume(i64 addrspace(1)* %obj.relocated.casted)
21cee313d2SEric Christopher; Need to delete unreachable gc.statepoint call
22cee313d2SEric Christopher  %obj2 = phi i64 addrspace(1)* [ %obj, %entry ]
23cee313d2SEric Christopher  call void @foo() [ "deopt"() ]
24cee313d2SEric Christopher  call void (...) @consume(i64 addrspace(1)* %obj2)
25cee313d2SEric Christopher  call void (...) @consume(i64 addrspace(1)* %obj)
26cee313d2SEric Christopher  ret void
27cee313d2SEric Christopher}
28cee313d2SEric Christopher
29cee313d2SEric Christopherdefine void @test7() gc "statepoint-example" {
30cee313d2SEric Christopher; CHECK-LABEL: test7
31cee313d2SEric Christopher; CHECK-NOT: gc.statepoint
32*bc93c2d7SMarek Kurdej; Need to delete unreachable gc.statepoint invoke - tested separately given
33cee313d2SEric Christopher; a correct implementation could only remove the instructions, not the block
34cee313d2SEric Christopher  ret void
35cee313d2SEric Christopher
36cee313d2SEric Christopherunreached:                                        ; preds = %unreached
37cee313d2SEric Christopher  %obj = phi i64 addrspace(1)* [ null, %unreached ]
38cee313d2SEric Christopher  call void @foo() [ "deopt"() ]
39cee313d2SEric Christopher  call void (...) @consume(i64 addrspace(1)* %obj)
40cee313d2SEric Christopher  br label %unreached
41cee313d2SEric Christopher}
42cee313d2SEric Christopher
43cee313d2SEric Christopherdefine void @test8() gc "statepoint-example" personality i32 ()* undef {
44cee313d2SEric Christopher; CHECK-LABEL: test8
45cee313d2SEric Christopher; CHECK-NOT: gc.statepoint
46cee313d2SEric Christopher; Bound the last check-not
47cee313d2SEric Christopher  ret void
48cee313d2SEric Christopher
49cee313d2SEric Christopherunreached:                                        ; No predecessors!
50cee313d2SEric Christopher  invoke void @foo() [ "deopt"() ]
51cee313d2SEric Christopher; CHECK-LABEL: @foo
52cee313d2SEric Christopher          to label %normal_return unwind label %exceptional_return
53cee313d2SEric Christopher
54cee313d2SEric Christophernormal_return:                                    ; preds = %unreached
55cee313d2SEric Christopher  ret void
56cee313d2SEric Christopher
57cee313d2SEric Christopherexceptional_return:                               ; preds = %unreached
58cee313d2SEric Christopher  %landing_pad4 = landingpad { i8*, i32 }
59cee313d2SEric Christopher          cleanup
60cee313d2SEric Christopher  ret void
61cee313d2SEric Christopher}
62cee313d2SEric Christopher
63cee313d2SEric Christopherdeclare void @foo()
64