106a8a867SPhilip Reames; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
206a8a867SPhilip Reames; RUN: opt < %s -rewrite-statepoints-for-gc -S  2>&1 | FileCheck %s
306a8a867SPhilip Reames; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S  2>&1 | FileCheck %s
4cee313d2SEric Christopher
5cee313d2SEric Christopherdeclare i1 @runtime_value() "gc-leaf-function"
6cee313d2SEric Christopher
706a8a867SPhilip Reames; derived %next base %base_obj
8cee313d2SEric Christopherdefine void @maybe_GEP(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
906a8a867SPhilip Reames; CHECK-LABEL: @maybe_GEP(
1006a8a867SPhilip Reames; CHECK-NEXT:  entry:
1106a8a867SPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
1206a8a867SPhilip Reames; CHECK:       loop:
1306a8a867SPhilip Reames; CHECK-NEXT:    [[DOT0:%.*]] = phi i64 addrspace(1)* [ [[BASE_OBJ:%.*]], [[ENTRY:%.*]] ], [ [[BASE_OBJ_RELOCATED_CASTED:%.*]], [[LOOP]] ]
1406a8a867SPhilip Reames; CHECK-NEXT:    [[CURRENT:%.*]] = phi i64 addrspace(1)* [ [[BASE_OBJ]], [[ENTRY]] ], [ [[NEXT_RELOCATED_CASTED:%.*]], [[LOOP]] ]
1506a8a867SPhilip Reames; CHECK-NEXT:    [[CONDITION:%.*]] = call i1 @runtime_value()
1606a8a867SPhilip Reames; CHECK-NEXT:    [[MAYBE_NEXT:%.*]] = getelementptr i64, i64 addrspace(1)* [[CURRENT]], i32 1
1706a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT:%.*]] = select i1 [[CONDITION]], i64 addrspace(1)* [[MAYBE_NEXT]], i64 addrspace(1)* [[CURRENT]]
18*c680eeabSNikita Popov; CHECK-NEXT:    [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[NEXT]], i64 addrspace(1)* [[DOT0]]) ]
1906a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
2006a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[NEXT_RELOCATED]] to i64 addrspace(1)*
2106a8a867SPhilip Reames; CHECK-NEXT:    [[BASE_OBJ_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
2206a8a867SPhilip Reames; CHECK-NEXT:    [[BASE_OBJ_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[BASE_OBJ_RELOCATED]] to i64 addrspace(1)*
2306a8a867SPhilip Reames; CHECK-NEXT:    br label [[LOOP]]
2406a8a867SPhilip Reames;
25cee313d2SEric Christopherentry:
26cee313d2SEric Christopher  br label %loop
27cee313d2SEric Christopher
28cee313d2SEric Christopherloop:                                             ; preds = %loop, %entry
29cee313d2SEric Christopher  %current = phi i64 addrspace(1)* [ %base_obj, %entry ], [ %next, %loop ]
30cee313d2SEric Christopher  %condition = call i1 @runtime_value()
31cee313d2SEric Christopher  %maybe_next = getelementptr i64, i64 addrspace(1)* %current, i32 1
32cee313d2SEric Christopher  %next = select i1 %condition, i64 addrspace(1)* %maybe_next, i64 addrspace(1)* %current
33cee313d2SEric Christopher  call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
34cee313d2SEric Christopher  br label %loop
35cee313d2SEric Christopher}
36cee313d2SEric Christopher
37cee313d2SEric Christopherdeclare void @do_safepoint()
38