1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
4 ; derived %next_element_ptr base %array_obj
5 define i32 @null_in_array(ptr addrspace(1) %array_obj) gc "statepoint-example" {
6 ; CHECK-LABEL: @null_in_array(
8 ; CHECK-NEXT: [[ARRAY_LEN_POINTER_I64:%.*]] = getelementptr i64, ptr addrspace(1) [[ARRAY_OBJ:%.*]], i32 1
9 ; CHECK-NEXT: [[ARRAY_LEN:%.*]] = load i32, ptr addrspace(1) [[ARRAY_LEN_POINTER_I64]], align 4
10 ; CHECK-NEXT: br label [[LOOP_CHECK:%.*]]
12 ; CHECK-NEXT: [[DOT0:%.*]] = phi ptr addrspace(1) [ [[ARRAY_OBJ]], [[ENTRY:%.*]] ], [ [[ARRAY_OBJ_RELOCATED_CASTED:%.*]], [[LOOP_BACK:%.*]] ]
13 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[NEXT_INDEX:%.*]], [[LOOP_BACK]] ]
14 ; CHECK-NEXT: [[CURRENT_ELEMENT_PTR:%.*]] = phi ptr addrspace(1) [ [[ARRAY_LEN_POINTER_I64]], [[ENTRY]] ], [ [[NEXT_ELEMENT_PTR_RELOCATED_CASTED:%.*]], [[LOOP_BACK]] ]
15 ; CHECK-NEXT: [[INDEX_LT:%.*]] = icmp ult i32 [[INDEX]], [[ARRAY_LEN]]
16 ; CHECK-NEXT: br i1 [[INDEX_LT]], label [[CHECK_FOR_NULL:%.*]], label [[NOT_FOUND:%.*]]
17 ; CHECK: check_for_null:
18 ; CHECK-NEXT: [[CURRENT_ELEMENT:%.*]] = load ptr addrspace(1), ptr addrspace(1) [[CURRENT_ELEMENT_PTR]], align 8
19 ; CHECK-NEXT: [[IS_NULL:%.*]] = icmp eq ptr addrspace(1) [[CURRENT_ELEMENT]], null
20 ; CHECK-NEXT: br i1 [[IS_NULL]], label [[FOUND:%.*]], label [[LOOP_BACK]]
22 ; CHECK-NEXT: [[NEXT_ELEMENT_PTR:%.*]] = getelementptr ptr addrspace(1), ptr addrspace(1) [[CURRENT_ELEMENT_PTR]], i32 1
23 ; CHECK-NEXT: [[NEXT_INDEX]] = add i32 [[INDEX]], 1
24 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr 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"(ptr addrspace(1) [[NEXT_ELEMENT_PTR]], ptr addrspace(1) [[DOT0]]) ]
25 ; CHECK-NEXT: [[NEXT_ELEMENT_PTR_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
26 ; CHECK-NEXT: [[ARRAY_OBJ_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
27 ; CHECK-NEXT: br label [[LOOP_CHECK]]
29 ; CHECK-NEXT: ret i32 -1
31 ; CHECK-NEXT: ret i32 [[INDEX]]
34 %array_len_pointer.i64 = getelementptr i64, ptr addrspace(1) %array_obj, i32 1
35 %array_len = load i32, ptr addrspace(1) %array_len_pointer.i64
38 loop_check: ; preds = %loop_back, %entry
39 %index = phi i32 [ 0, %entry ], [ %next_index, %loop_back ]
40 %current_element_ptr = phi ptr addrspace(1) [ %array_len_pointer.i64, %entry ], [ %next_element_ptr, %loop_back ]
41 %index_lt = icmp ult i32 %index, %array_len
42 br i1 %index_lt, label %check_for_null, label %not_found
44 check_for_null: ; preds = %loop_check
45 %current_element = load ptr addrspace(1), ptr addrspace(1) %current_element_ptr
46 %is_null = icmp eq ptr addrspace(1) %current_element, null
47 br i1 %is_null, label %found, label %loop_back
49 loop_back: ; preds = %check_for_null
50 %next_element_ptr = getelementptr ptr addrspace(1), ptr addrspace(1) %current_element_ptr, i32 1
51 %next_index = add i32 %index, 1
52 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
55 not_found: ; preds = %loop_check
58 found: ; preds = %check_for_null
62 declare void @do_safepoint()