From 6335446c99eb7263b8ae89a071df8a2cd66940d5 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 27 Oct 2020 14:50:00 +0700 Subject: [PATCH] [Test] One more range check test --- .../Transforms/IndVarSimplify/predicated_ranges.ll | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll index c62fe78..9e6908c 100644 --- a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll +++ b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll @@ -567,4 +567,58 @@ fail: 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} -- 2.7.4