1; RUN: opt -S -loop-predication < %s 2>&1 | FileCheck %s 2; RUN: opt -S -passes='require<scalar-evolution>,loop(loop-predication)' < %s 2>&1 | FileCheck %s 3 4declare void @llvm.experimental.guard(i1, ...) 5 6define i32 @test_visited(i32* %array, i32 %length, i32 %n, i32 %x) { 7; CHECK-LABEL: @test_visited 8entry: 9 %tmp5 = icmp eq i32 %n, 0 10 br i1 %tmp5, label %exit, label %loop.preheader 11 12loop.preheader: 13; CHECK: loop.preheader: 14; CHECK: [[limit_check:[^ ]+]] = icmp ule i32 %n, %length 15; CHECK-NEXT: [[first_iteration_check:[^ ]+]] = icmp ult i32 0, %length 16; CHECK-NEXT: [[wide_cond:[^ ]+]] = and i1 [[first_iteration_check]], [[limit_check]] 17; CHECK-NEXT: br label %loop 18 br label %loop 19 20loop: 21; CHECK: loop: 22; CHECK: %unrelated.cond = icmp eq i32 %x, %i 23; CHECK: [[guard_cond:[^ ]+]] = and i1 %unrelated.cond, [[wide_cond]] 24; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[guard_cond]], i32 9) [ "deopt"() ] 25 %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ] 26 %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ] 27 %within.bounds = icmp ult i32 %i, %length 28 %unrelated.cond = icmp eq i32 %x, %i 29 %guard.cond.2 = and i1 %within.bounds, %unrelated.cond 30 %guard.cond.3 = and i1 %guard.cond.2, %unrelated.cond 31 %guard.cond.4 = and i1 %guard.cond.3, %guard.cond.2 32 %guard.cond.5 = and i1 %guard.cond.4, %guard.cond.3 33 %guard.cond.6 = and i1 %guard.cond.5, %guard.cond.4 34 %guard.cond.7 = and i1 %guard.cond.6, %guard.cond.5 35 %guard.cond.8 = and i1 %guard.cond.7, %guard.cond.6 36 %guard.cond.9 = and i1 %guard.cond.8, %guard.cond.7 37 %guard.cond.10 = and i1 %guard.cond.9, %guard.cond.8 38 %guard.cond.11 = and i1 %guard.cond.10, %guard.cond.9 39 %guard.cond.12 = and i1 %guard.cond.11, %guard.cond.10 40 %guard.cond.13 = and i1 %guard.cond.12, %guard.cond.11 41 %guard.cond.14 = and i1 %guard.cond.13, %guard.cond.12 42 %guard.cond.15 = and i1 %guard.cond.14, %guard.cond.13 43 %guard.cond.16 = and i1 %guard.cond.15, %guard.cond.14 44 %guard.cond.17 = and i1 %guard.cond.16, %guard.cond.15 45 %guard.cond.18 = and i1 %guard.cond.17, %guard.cond.16 46 %guard.cond.19 = and i1 %guard.cond.18, %guard.cond.17 47 %guard.cond.20 = and i1 %guard.cond.19, %guard.cond.18 48 %guard.cond.21 = and i1 %guard.cond.20, %guard.cond.19 49 %guard.cond.22 = and i1 %guard.cond.21, %guard.cond.20 50 %guard.cond.23 = and i1 %guard.cond.22, %guard.cond.21 51 %guard.cond.24 = and i1 %guard.cond.23, %guard.cond.22 52 %guard.cond.25 = and i1 %guard.cond.24, %guard.cond.23 53 %guard.cond.26 = and i1 %guard.cond.25, %guard.cond.24 54 %guard.cond.27 = and i1 %guard.cond.26, %guard.cond.25 55 %guard.cond.28 = and i1 %guard.cond.27, %guard.cond.26 56 %guard.cond.29 = and i1 %guard.cond.28, %guard.cond.27 57 %guard.cond.30 = and i1 %guard.cond.29, %guard.cond.28 58 %guard.cond.31 = and i1 %guard.cond.30, %guard.cond.29 59 %guard.cond.32 = and i1 %guard.cond.31, %guard.cond.30 60 %guard.cond.33 = and i1 %guard.cond.32, %guard.cond.31 61 %guard.cond.34 = and i1 %guard.cond.33, %guard.cond.32 62 %guard.cond.35 = and i1 %guard.cond.34, %guard.cond.33 63 %guard.cond.36 = and i1 %guard.cond.35, %guard.cond.34 64 %guard.cond.37 = and i1 %guard.cond.36, %guard.cond.35 65 %guard.cond.38 = and i1 %guard.cond.37, %guard.cond.36 66 %guard.cond.39 = and i1 %guard.cond.38, %guard.cond.37 67 %guard.cond.40 = and i1 %guard.cond.39, %guard.cond.38 68 %guard.cond.41 = and i1 %guard.cond.40, %guard.cond.39 69 %guard.cond.42 = and i1 %guard.cond.41, %guard.cond.40 70 %guard.cond.43 = and i1 %guard.cond.42, %guard.cond.41 71 %guard.cond.44 = and i1 %guard.cond.43, %guard.cond.42 72 %guard.cond.45 = and i1 %guard.cond.44, %guard.cond.43 73 %guard.cond.46 = and i1 %guard.cond.45, %guard.cond.44 74 %guard.cond.47 = and i1 %guard.cond.46, %guard.cond.45 75 %guard.cond.48 = and i1 %guard.cond.47, %guard.cond.46 76 %guard.cond.49 = and i1 %guard.cond.48, %guard.cond.47 77 %guard.cond.50 = and i1 %guard.cond.49, %guard.cond.48 78 %guard.cond.51 = and i1 %guard.cond.50, %guard.cond.49 79 %guard.cond.52 = and i1 %guard.cond.51, %guard.cond.50 80 %guard.cond.53 = and i1 %guard.cond.52, %guard.cond.51 81 %guard.cond.54 = and i1 %guard.cond.53, %guard.cond.52 82 %guard.cond.55 = and i1 %guard.cond.54, %guard.cond.53 83 %guard.cond.56 = and i1 %guard.cond.55, %guard.cond.54 84 %guard.cond.57 = and i1 %guard.cond.56, %guard.cond.55 85 %guard.cond.58 = and i1 %guard.cond.57, %guard.cond.56 86 %guard.cond.59 = and i1 %guard.cond.58, %guard.cond.57 87 %guard.cond.60 = and i1 %guard.cond.59, %guard.cond.58 88 %guard.cond.61 = and i1 %guard.cond.60, %guard.cond.59 89 %guard.cond.62 = and i1 %guard.cond.61, %guard.cond.60 90 %guard.cond.63 = and i1 %guard.cond.62, %guard.cond.61 91 %guard.cond.64 = and i1 %guard.cond.63, %guard.cond.62 92 %guard.cond.65 = and i1 %guard.cond.64, %guard.cond.63 93 %guard.cond.66 = and i1 %guard.cond.65, %guard.cond.64 94 %guard.cond.67 = and i1 %guard.cond.66, %guard.cond.65 95 %guard.cond.68 = and i1 %guard.cond.67, %guard.cond.66 96 %guard.cond.69 = and i1 %guard.cond.68, %guard.cond.67 97 %guard.cond.70 = and i1 %guard.cond.69, %guard.cond.68 98 %guard.cond.71 = and i1 %guard.cond.70, %guard.cond.69 99 %guard.cond.72 = and i1 %guard.cond.71, %guard.cond.70 100 %guard.cond.73 = and i1 %guard.cond.72, %guard.cond.71 101 %guard.cond.74 = and i1 %guard.cond.73, %guard.cond.72 102 %guard.cond.75 = and i1 %guard.cond.74, %guard.cond.73 103 %guard.cond.76 = and i1 %guard.cond.75, %guard.cond.74 104 %guard.cond.77 = and i1 %guard.cond.76, %guard.cond.75 105 %guard.cond.78 = and i1 %guard.cond.77, %guard.cond.76 106 %guard.cond.79 = and i1 %guard.cond.78, %guard.cond.77 107 %guard.cond.80 = and i1 %guard.cond.79, %guard.cond.78 108 %guard.cond.81 = and i1 %guard.cond.80, %guard.cond.79 109 %guard.cond.82 = and i1 %guard.cond.81, %guard.cond.80 110 %guard.cond.83 = and i1 %guard.cond.82, %guard.cond.81 111 %guard.cond.84 = and i1 %guard.cond.83, %guard.cond.82 112 %guard.cond.85 = and i1 %guard.cond.84, %guard.cond.83 113 %guard.cond.86 = and i1 %guard.cond.85, %guard.cond.84 114 %guard.cond.87 = and i1 %guard.cond.86, %guard.cond.85 115 %guard.cond.88 = and i1 %guard.cond.87, %guard.cond.86 116 %guard.cond.89 = and i1 %guard.cond.88, %guard.cond.87 117 %guard.cond.90 = and i1 %guard.cond.89, %guard.cond.88 118 %guard.cond.91 = and i1 %guard.cond.90, %guard.cond.89 119 %guard.cond.92 = and i1 %guard.cond.91, %guard.cond.90 120 %guard.cond.93 = and i1 %guard.cond.92, %guard.cond.91 121 %guard.cond.94 = and i1 %guard.cond.93, %guard.cond.92 122 %guard.cond.95 = and i1 %guard.cond.94, %guard.cond.93 123 %guard.cond.96 = and i1 %guard.cond.95, %guard.cond.94 124 %guard.cond.97 = and i1 %guard.cond.96, %guard.cond.95 125 %guard.cond.98 = and i1 %guard.cond.97, %guard.cond.96 126 %guard.cond.99 = and i1 %guard.cond.98, %guard.cond.97 127 call void (i1, ...) @llvm.experimental.guard(i1 %guard.cond.99, i32 9) [ "deopt"() ] 128 129 %i.i64 = zext i32 %i to i64 130 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64 131 %array.i = load i32, i32* %array.i.ptr, align 4 132 %loop.acc.next = add i32 %loop.acc, %array.i 133 134 %i.next = add nuw i32 %i, 1 135 %continue = icmp ult i32 %i.next, %n 136 br i1 %continue, label %loop, label %exit 137 138exit: 139 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ] 140 ret i32 %result 141}