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 void @site_for_call_safpeoint()
6cee313d2SEric Christopher
706a8a867SPhilip Reames; derived %merged_value base %merged_value.base
8cee313d2SEric Christopherdefine i64 addrspace(1)* @test(i64 addrspace(1)* %base_obj_x, i64 addrspace(1)* %base_obj_y, i1 %runtime_condition_x, i1 %runtime_condition_y) gc "statepoint-example" {
906a8a867SPhilip Reames; CHECK-LABEL: @test(
1006a8a867SPhilip Reames; CHECK-NEXT:  entry:
1106a8a867SPhilip Reames; CHECK-NEXT:    br i1 [[RUNTIME_CONDITION_X:%.*]], label [[HERE:%.*]], label [[THERE:%.*]]
1206a8a867SPhilip Reames; CHECK:       here:
1306a8a867SPhilip Reames; CHECK-NEXT:    br i1 [[RUNTIME_CONDITION_Y:%.*]], label [[BUMP_HERE_A:%.*]], label [[BUMP_HERE_B:%.*]]
1406a8a867SPhilip Reames; CHECK:       bump_here_a:
1506a8a867SPhilip Reames; CHECK-NEXT:    [[X_A:%.*]] = getelementptr i64, i64 addrspace(1)* [[BASE_OBJ_X:%.*]], i32 1
1606a8a867SPhilip Reames; CHECK-NEXT:    br label [[MERGE_HERE:%.*]]
1706a8a867SPhilip Reames; CHECK:       bump_here_b:
1806a8a867SPhilip Reames; CHECK-NEXT:    [[X_B:%.*]] = getelementptr i64, i64 addrspace(1)* [[BASE_OBJ_Y:%.*]], i32 2
1906a8a867SPhilip Reames; CHECK-NEXT:    br label [[MERGE_HERE]]
2006a8a867SPhilip Reames; CHECK:       merge_here:
2106a8a867SPhilip Reames; CHECK-NEXT:    [[X_BASE:%.*]] = phi i64 addrspace(1)* [ [[BASE_OBJ_X]], [[BUMP_HERE_A]] ], [ [[BASE_OBJ_Y]], [[BUMP_HERE_B]] ], !is_base_value !0
2206a8a867SPhilip Reames; CHECK-NEXT:    [[X:%.*]] = phi i64 addrspace(1)* [ [[X_A]], [[BUMP_HERE_A]] ], [ [[X_B]], [[BUMP_HERE_B]] ]
2306a8a867SPhilip Reames; CHECK-NEXT:    br label [[MERGE:%.*]]
2406a8a867SPhilip Reames; CHECK:       there:
2506a8a867SPhilip Reames; CHECK-NEXT:    [[Y:%.*]] = getelementptr i64, i64 addrspace(1)* [[BASE_OBJ_Y]], i32 1
2606a8a867SPhilip Reames; CHECK-NEXT:    br label [[MERGE]]
2706a8a867SPhilip Reames; CHECK:       merge:
2806a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE_BASE:%.*]] = phi i64 addrspace(1)* [ [[X_BASE]], [[MERGE_HERE]] ], [ [[BASE_OBJ_Y]], [[THERE]] ], !is_base_value !0
2906a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE:%.*]] = phi i64 addrspace(1)* [ [[X]], [[MERGE_HERE]] ], [ [[Y]], [[THERE]] ]
30*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 ()) @site_for_call_safpeoint, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[MERGED_VALUE]], i64 addrspace(1)* [[MERGED_VALUE_BASE]]) ]
3106a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
3206a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[MERGED_VALUE_RELOCATED]] to i64 addrspace(1)*
3306a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE_BASE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
3406a8a867SPhilip Reames; CHECK-NEXT:    [[MERGED_VALUE_BASE_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[MERGED_VALUE_BASE_RELOCATED]] to i64 addrspace(1)*
3506a8a867SPhilip Reames; CHECK-NEXT:    ret i64 addrspace(1)* [[MERGED_VALUE_RELOCATED_CASTED]]
3606a8a867SPhilip Reames;
37cee313d2SEric Christopherentry:
38cee313d2SEric Christopher  br i1 %runtime_condition_x, label %here, label %there
39cee313d2SEric Christopher
40cee313d2SEric Christopherhere:                                             ; preds = %entry
41cee313d2SEric Christopher  br i1 %runtime_condition_y, label %bump_here_a, label %bump_here_b
42cee313d2SEric Christopher
43cee313d2SEric Christopherbump_here_a:                                      ; preds = %here
44cee313d2SEric Christopher  %x_a = getelementptr i64, i64 addrspace(1)* %base_obj_x, i32 1
45cee313d2SEric Christopher  br label %merge_here
46cee313d2SEric Christopher
47cee313d2SEric Christopherbump_here_b:                                      ; preds = %here
48cee313d2SEric Christopher  %x_b = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 2
49cee313d2SEric Christopher  br label %merge_here
50cee313d2SEric Christopher
51cee313d2SEric Christophermerge_here:                                       ; preds = %bump_here_b, %bump_here_a
52cee313d2SEric Christopher  %x = phi i64 addrspace(1)* [ %x_a, %bump_here_a ], [ %x_b, %bump_here_b ]
53cee313d2SEric Christopher  br label %merge
54cee313d2SEric Christopher
55cee313d2SEric Christopherthere:                                            ; preds = %entry
56cee313d2SEric Christopher  %y = getelementptr i64, i64 addrspace(1)* %base_obj_y, i32 1
57cee313d2SEric Christopher  br label %merge
58cee313d2SEric Christopher
59cee313d2SEric Christophermerge:                                            ; preds = %there, %merge_here
60cee313d2SEric Christopher  %merged_value = phi i64 addrspace(1)* [ %x, %merge_here ], [ %y, %there ]
61cee313d2SEric Christopher  call void @site_for_call_safpeoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
62cee313d2SEric Christopher  ret i64 addrspace(1)* %merged_value
63cee313d2SEric Christopher}
64