1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s 3 4; Trip counts with trivial exit conditions. 5 6define void @a(i64 %n) nounwind { 7; CHECK-LABEL: 'a' 8; CHECK-NEXT: Determining loop execution counts for: @a 9; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count. 10; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count. 11; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. 12; 13entry: 14 %t0 = icmp sgt i64 %n, 0 15 br i1 %t0, label %loop, label %return 16 17loop: 18 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 19 %i.next = add nsw i64 %i, 1 20 %exitcond = icmp eq i64 %i.next, %n 21 br i1 false, label %return, label %loop 22 23return: 24 ret void 25} 26define void @b(i64 %n) nounwind { 27; CHECK-LABEL: 'b' 28; CHECK-NEXT: Determining loop execution counts for: @b 29; CHECK-NEXT: Loop %loop: backedge-taken count is i1 false 30; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i1 false 31; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i1 false 32; CHECK-NEXT: Loop %loop: Trip multiple is 1 33; 34entry: 35 %t0 = icmp sgt i64 %n, 0 36 br i1 %t0, label %loop, label %return 37 38loop: 39 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 40 %i.next = add nsw i64 %i, 1 41 %exitcond = icmp eq i64 %i.next, %n 42 br i1 true, label %return, label %loop 43 44return: 45 ret void 46} 47define void @c(i64 %n) nounwind { 48; CHECK-LABEL: 'c' 49; CHECK-NEXT: Determining loop execution counts for: @c 50; CHECK-NEXT: Loop %loop: backedge-taken count is i1 false 51; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i1 false 52; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i1 false 53; CHECK-NEXT: Loop %loop: Trip multiple is 1 54; 55entry: 56 %t0 = icmp sgt i64 %n, 0 57 br i1 %t0, label %loop, label %return 58 59loop: 60 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 61 %i.next = add nsw i64 %i, 1 62 %exitcond = icmp eq i64 %i.next, %n 63 br i1 false, label %loop, label %return 64 65return: 66 ret void 67} 68define void @d(i64 %n) nounwind { 69; CHECK-LABEL: 'd' 70; CHECK-NEXT: Determining loop execution counts for: @d 71; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count. 72; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count. 73; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. 74; 75entry: 76 %t0 = icmp sgt i64 %n, 0 77 br i1 %t0, label %loop, label %return 78 79loop: 80 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 81 %i.next = add nsw i64 %i, 1 82 %exitcond = icmp eq i64 %i.next, %n 83 br i1 true, label %loop, label %return 84 85return: 86 ret void 87} 88 89; Trip counts for non-polynomial iterations. It's theoretically possible 90; to compute a maximum count for these, but short of that, ScalarEvolution 91; should return unknown. 92 93; PR7416 94declare i1 @g() nounwind 95 96define void @nonpolynomial() { 97; CHECK-LABEL: 'nonpolynomial' 98; CHECK-NEXT: Determining loop execution counts for: @nonpolynomial 99; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count. 100; CHECK-NEXT: Loop %loophead: Unpredictable constant max backedge-taken count. 101; CHECK-NEXT: Loop %loophead: Unpredictable symbolic max backedge-taken count. 102; 103entry: 104 br label %loophead 105loophead: 106 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2] 107 %y = icmp slt i32 %x, 100 108 br i1 %y, label %loopbody, label %retbb 109loopbody: 110 %z = call i1 @g() 111 br i1 %z, label %bb1, label %bb2 112bb1: 113 %x.1 = add i32 %x, 2 114 br label %loophead 115bb2: 116 %x.2 = add i32 %x, 3 117 br label %loophead 118retbb: 119 ret void 120} 121 122; PHI nodes with all constant operands. 123 124define void @constant_phi_operands() nounwind { 125; CHECK-LABEL: 'constant_phi_operands' 126; CHECK-NEXT: Determining loop execution counts for: @constant_phi_operands 127; CHECK-NEXT: Loop %loop: backedge-taken count is i32 1 128; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 1 129; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i32 1 130; CHECK-NEXT: Loop %loop: Trip multiple is 2 131; 132entry: 133 br label %loop 134 135loop: 136 %i = phi i64 [ 1, %loop ], [ 0, %entry ] 137 %exitcond = icmp eq i64 %i, 1 138 br i1 %exitcond, label %return, label %loop 139 140return: 141 ret void 142} 143 144; PR16130: Loop exit depends on an 'or' expression. 145; One side of the expression test against a value that will be skipped. 146; We can't assume undefined behavior just because we have an NSW flag. 147; 148define void @exit_orcond_nsw(ptr %a) nounwind { 149; CHECK-LABEL: 'exit_orcond_nsw' 150; CHECK-NEXT: Determining loop execution counts for: @exit_orcond_nsw 151; CHECK-NEXT: Loop %for.body.i: Unpredictable backedge-taken count. 152; CHECK-NEXT: Loop %for.body.i: constant max backedge-taken count is i32 1 153; CHECK-NEXT: Loop %for.body.i: symbolic max backedge-taken count is i32 1 154; 155entry: 156 br label %for.body.i 157 158for.body.i: ; preds = %for.body.i, %entry 159 %b.01.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ] 160 %tobool.i = icmp ne i32 %b.01.i, 0 161 %add.i = add nsw i32 %b.01.i, 8 162 %cmp.i = icmp eq i32 %add.i, 13 163 %or.cond = or i1 %tobool.i, %cmp.i 164 br i1 %or.cond, label %exit, label %for.body.i 165 166exit: ; preds = %for.body.i 167 %b.01.i.lcssa = phi i32 [ %b.01.i, %for.body.i ] 168 store i32 %b.01.i.lcssa, ptr %a, align 4 169 ret void 170} 171