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
506a8a867SPhilip Reames; derived %next.i64 base %base_obj
6cee313d2SEric Christopher
7cee313d2SEric Christopherdefine void @test(i64 addrspace(1)* %base_obj) gc "statepoint-example" {
806a8a867SPhilip Reames; CHECK-LABEL: @test(
906a8a867SPhilip Reames; CHECK-NEXT:  entry:
1006a8a867SPhilip Reames; CHECK-NEXT:    [[OBJ:%.*]] = getelementptr i64, i64 addrspace(1)* [[BASE_OBJ:%.*]], i32 1
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)* [ [[OBJ]], [[ENTRY]] ], [ [[NEXT_I64_RELOCATED_CASTED:%.*]], [[LOOP]] ]
1506a8a867SPhilip Reames; CHECK-NEXT:    [[CURRENT_I32:%.*]] = bitcast i64 addrspace(1)* [[CURRENT]] to i32 addrspace(1)*
1606a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_I32:%.*]] = getelementptr i32, i32 addrspace(1)* [[CURRENT_I32]], i32 1
1706a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_I64:%.*]] = bitcast i32 addrspace(1)* [[NEXT_I32]] to i64 addrspace(1)*
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]], i64 addrspace(1)* [[DOT0]]) ]
1906a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_I64_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
2006a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_I64_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[NEXT_I64_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  %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
27cee313d2SEric Christopher  br label %loop
28cee313d2SEric Christopher
29cee313d2SEric Christopherloop:                                             ; preds = %loop, %entry
30cee313d2SEric Christopher  %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next.i64, %loop ]
31cee313d2SEric Christopher  %current.i32 = bitcast i64 addrspace(1)* %current to i32 addrspace(1)*
32cee313d2SEric Christopher  %next.i32 = getelementptr i32, i32 addrspace(1)* %current.i32, i32 1
33cee313d2SEric Christopher  %next.i64 = bitcast i32 addrspace(1)* %next.i32 to i64 addrspace(1)*
34cee313d2SEric Christopher  call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
35cee313d2SEric Christopher  br label %loop
36cee313d2SEric Christopher}
37cee313d2SEric Christopher
38cee313d2SEric Christopherdeclare void @do_safepoint()
39