unreachable
}
+define void @test_can_predicate_trunc_unsigned(i32* %p, i32* %arr) {
+; CHECK-LABEL: @test_can_predicate_trunc_unsigned(
+; CHECK-NEXT: preheader:
+; CHECK-NEXT: [[LEN:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: [[START:%.*]] = zext i32 [[LEN]] to i64
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[START]], [[PREHEADER:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
+; CHECK-NEXT: [[ZERO_COND:%.*]] = icmp eq i64 [[IV]], 0
+; CHECK-NEXT: br i1 [[ZERO_COND]], label [[EXIT:%.*]], label [[RANGE_CHECK_BLOCK:%.*]]
+; CHECK: range_check_block:
+; CHECK-NEXT: [[IV_NEXT]] = sub nsw i64 [[IV]], 1
+; CHECK-NEXT: [[NARROW:%.*]] = trunc i64 [[IV_NEXT]] to i32
+; CHECK-NEXT: [[RANGE_CHECK:%.*]] = icmp ult i32 [[NARROW]], [[LEN]]
+; CHECK-NEXT: br i1 [[RANGE_CHECK]], label [[BACKEDGE]], label [[FAIL:%.*]]
+; CHECK: backedge:
+; CHECK-NEXT: [[EL_PTR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i64 [[IV]]
+; CHECK-NEXT: [[EL:%.*]] = load i32, i32* [[EL_PTR]], align 4
+; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp eq i32 [[EL]], 0
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK: fail:
+; CHECK-NEXT: unreachable
+;
+preheader:
+ %len = load i32, i32* %p
+ %start = zext i32 %len to i64
+ br label %loop
+
+loop:
+ %iv = phi i64 [%start, %preheader], [%iv.next, %backedge]
+ %zero_cond = icmp eq i64 %iv, 0
+ br i1 %zero_cond, label %exit, label %range_check_block
+
+range_check_block:
+ %iv.next = sub i64 %iv, 1
+ %narrow = trunc i64 %iv.next to i32
+ %range_check = icmp ult i32 %narrow, %len
+ br i1 %range_check, label %backedge, label %fail
+
+backedge:
+ %el.ptr = getelementptr i32, i32* %arr, i64 %iv
+ %el = load i32, i32* %el.ptr
+ %loop.cond = icmp eq i32 %el, 0
+ br i1 %loop.cond, label %loop, label %exit
+
+exit:
+ ret void
+
+fail:
+ unreachable
+}
+
!0 = !{i32 0, i32 2147483647}