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_element_ptr base %array_obj
6cee313d2SEric Christopherdefine i32 @null_in_array(i64 addrspace(1)* %array_obj) gc "statepoint-example" {
706a8a867SPhilip Reames; CHECK-LABEL: @null_in_array(
806a8a867SPhilip Reames; CHECK-NEXT:  entry:
906a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_LEN_POINTER_I64:%.*]] = getelementptr i64, i64 addrspace(1)* [[ARRAY_OBJ:%.*]], i32 1
1006a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_LEN_POINTER_I32:%.*]] = bitcast i64 addrspace(1)* [[ARRAY_LEN_POINTER_I64]] to i32 addrspace(1)*
1106a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_LEN:%.*]] = load i32, i32 addrspace(1)* [[ARRAY_LEN_POINTER_I32]], align 4
1206a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_ELEMS:%.*]] = bitcast i32 addrspace(1)* [[ARRAY_LEN_POINTER_I32]] to i64 addrspace(1)* addrspace(1)*
1306a8a867SPhilip Reames; CHECK-NEXT:    br label [[LOOP_CHECK:%.*]]
1406a8a867SPhilip Reames; CHECK:       loop_check:
1506a8a867SPhilip Reames; CHECK-NEXT:    [[DOT0:%.*]] = phi i64 addrspace(1)* [ [[ARRAY_OBJ]], [[ENTRY:%.*]] ], [ [[ARRAY_OBJ_RELOCATED_CASTED:%.*]], [[LOOP_BACK:%.*]] ]
1606a8a867SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[NEXT_INDEX:%.*]], [[LOOP_BACK]] ]
1706a8a867SPhilip Reames; CHECK-NEXT:    [[CURRENT_ELEMENT_PTR:%.*]] = phi i64 addrspace(1)* addrspace(1)* [ [[ARRAY_ELEMS]], [[ENTRY]] ], [ [[NEXT_ELEMENT_PTR_RELOCATED_CASTED:%.*]], [[LOOP_BACK]] ]
1806a8a867SPhilip Reames; CHECK-NEXT:    [[INDEX_LT:%.*]] = icmp ult i32 [[INDEX]], [[ARRAY_LEN]]
1906a8a867SPhilip Reames; CHECK-NEXT:    br i1 [[INDEX_LT]], label [[CHECK_FOR_NULL:%.*]], label [[NOT_FOUND:%.*]]
2006a8a867SPhilip Reames; CHECK:       check_for_null:
2106a8a867SPhilip Reames; CHECK-NEXT:    [[CURRENT_ELEMENT:%.*]] = load i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* [[CURRENT_ELEMENT_PTR]], align 8
2206a8a867SPhilip Reames; CHECK-NEXT:    [[IS_NULL:%.*]] = icmp eq i64 addrspace(1)* [[CURRENT_ELEMENT]], null
2306a8a867SPhilip Reames; CHECK-NEXT:    br i1 [[IS_NULL]], label [[FOUND:%.*]], label [[LOOP_BACK]]
2406a8a867SPhilip Reames; CHECK:       loop_back:
2506a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_ELEMENT_PTR:%.*]] = getelementptr i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* [[CURRENT_ELEMENT_PTR]], i32 1
2606a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_INDEX]] = add i32 [[INDEX]], 1
27*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)* addrspace(1)* [[NEXT_ELEMENT_PTR]], i64 addrspace(1)* [[DOT0]]) ]
2806a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_ELEMENT_PTR_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
2906a8a867SPhilip Reames; CHECK-NEXT:    [[NEXT_ELEMENT_PTR_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[NEXT_ELEMENT_PTR_RELOCATED]] to i64 addrspace(1)* addrspace(1)*
3006a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_OBJ_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
3106a8a867SPhilip Reames; CHECK-NEXT:    [[ARRAY_OBJ_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[ARRAY_OBJ_RELOCATED]] to i64 addrspace(1)*
3206a8a867SPhilip Reames; CHECK-NEXT:    br label [[LOOP_CHECK]]
3306a8a867SPhilip Reames; CHECK:       not_found:
3406a8a867SPhilip Reames; CHECK-NEXT:    ret i32 -1
3506a8a867SPhilip Reames; CHECK:       found:
3606a8a867SPhilip Reames; CHECK-NEXT:    ret i32 [[INDEX]]
3706a8a867SPhilip Reames;
38cee313d2SEric Christopherentry:
39cee313d2SEric Christopher  %array_len_pointer.i64 = getelementptr i64, i64 addrspace(1)* %array_obj, i32 1
40cee313d2SEric Christopher  %array_len_pointer.i32 = bitcast i64 addrspace(1)* %array_len_pointer.i64 to i32 addrspace(1)*
41cee313d2SEric Christopher  %array_len = load i32, i32 addrspace(1)* %array_len_pointer.i32
42cee313d2SEric Christopher  %array_elems = bitcast i32 addrspace(1)* %array_len_pointer.i32 to i64 addrspace(1)* addrspace(1)*
43cee313d2SEric Christopher  br label %loop_check
44cee313d2SEric Christopher
45cee313d2SEric Christopherloop_check:                                       ; preds = %loop_back, %entry
46cee313d2SEric Christopher  %index = phi i32 [ 0, %entry ], [ %next_index, %loop_back ]
47cee313d2SEric Christopher  %current_element_ptr = phi i64 addrspace(1)* addrspace(1)* [ %array_elems, %entry ], [ %next_element_ptr, %loop_back ]
48cee313d2SEric Christopher  %index_lt = icmp ult i32 %index, %array_len
49cee313d2SEric Christopher  br i1 %index_lt, label %check_for_null, label %not_found
50cee313d2SEric Christopher
51cee313d2SEric Christophercheck_for_null:                                   ; preds = %loop_check
52cee313d2SEric Christopher  %current_element = load i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr
53cee313d2SEric Christopher  %is_null = icmp eq i64 addrspace(1)* %current_element, null
54cee313d2SEric Christopher  br i1 %is_null, label %found, label %loop_back
55cee313d2SEric Christopher
56cee313d2SEric Christopherloop_back:                                        ; preds = %check_for_null
57cee313d2SEric Christopher  %next_element_ptr = getelementptr i64 addrspace(1)*, i64 addrspace(1)* addrspace(1)* %current_element_ptr, i32 1
58cee313d2SEric Christopher  %next_index = add i32 %index, 1
59cee313d2SEric Christopher  call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
60cee313d2SEric Christopher  br label %loop_check
61cee313d2SEric Christopher
62cee313d2SEric Christophernot_found:                                        ; preds = %loop_check
63cee313d2SEric Christopher  ret i32 -1
64cee313d2SEric Christopher
65cee313d2SEric Christopherfound:                                            ; preds = %check_for_null
66cee313d2SEric Christopher  ret i32 %index
67cee313d2SEric Christopher}
68cee313d2SEric Christopher
69cee313d2SEric Christopherdeclare void @do_safepoint()
70