1; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s 2 3; Trip counts with trivial exit conditions. 4 5; CHECK: Determining loop execution counts for: @a 6; CHECK: Loop %loop: Unpredictable backedge-taken count. 7; CHECK: Loop %loop: Unpredictable max backedge-taken count. 8 9; CHECK: Determining loop execution counts for: @b 10; CHECK: Loop %loop: backedge-taken count is false 11; CHECK: Loop %loop: max backedge-taken count is false 12 13; CHECK: Determining loop execution counts for: @c 14; CHECK: Loop %loop: backedge-taken count is false 15; CHECK: Loop %loop: max backedge-taken count is false 16 17; CHECK: Determining loop execution counts for: @d 18; CHECK: Loop %loop: Unpredictable backedge-taken count. 19; CHECK: Loop %loop: Unpredictable max backedge-taken count. 20 21define void @a(i64 %n) nounwind { 22entry: 23 %t0 = icmp sgt i64 %n, 0 24 br i1 %t0, label %loop, label %return 25 26loop: 27 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 28 %i.next = add nsw i64 %i, 1 29 %exitcond = icmp eq i64 %i.next, %n 30 br i1 false, label %return, label %loop 31 32return: 33 ret void 34} 35define void @b(i64 %n) nounwind { 36entry: 37 %t0 = icmp sgt i64 %n, 0 38 br i1 %t0, label %loop, label %return 39 40loop: 41 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 42 %i.next = add nsw i64 %i, 1 43 %exitcond = icmp eq i64 %i.next, %n 44 br i1 true, label %return, label %loop 45 46return: 47 ret void 48} 49define void @c(i64 %n) nounwind { 50entry: 51 %t0 = icmp sgt i64 %n, 0 52 br i1 %t0, label %loop, label %return 53 54loop: 55 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 56 %i.next = add nsw i64 %i, 1 57 %exitcond = icmp eq i64 %i.next, %n 58 br i1 false, label %loop, label %return 59 60return: 61 ret void 62} 63define void @d(i64 %n) nounwind { 64entry: 65 %t0 = icmp sgt i64 %n, 0 66 br i1 %t0, label %loop, label %return 67 68loop: 69 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ] 70 %i.next = add nsw i64 %i, 1 71 %exitcond = icmp eq i64 %i.next, %n 72 br i1 true, label %loop, label %return 73 74return: 75 ret void 76} 77 78; Trip counts for non-polynomial iterations. It's theoretically possible 79; to compute a maximum count for these, but short of that, ScalarEvolution 80; should return unknown. 81 82; PR7416 83; CHECK: Determining loop execution counts for: @nonpolynomial 84; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count 85; CHECK-NEXT: Loop %loophead: Unpredictable max backedge-taken count 86 87declare i1 @g() nounwind 88 89define void @nonpolynomial() { 90entry: 91 br label %loophead 92loophead: 93 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2] 94 %y = icmp slt i32 %x, 100 95 br i1 %y, label %loopbody, label %retbb 96loopbody: 97 %z = call i1 @g() 98 br i1 %z, label %bb1, label %bb2 99bb1: 100 %x.1 = add i32 %x, 2 101 br label %loophead 102bb2: 103 %x.2 = add i32 %x, 3 104 br label %loophead 105retbb: 106 ret void 107} 108 109; PHI nodes with all constant operands. 110 111; CHECK: Determining loop execution counts for: @constant_phi_operands 112; CHECK: Loop %loop: backedge-taken count is 1 113; CHECK: Loop %loop: max backedge-taken count is 1 114 115define void @constant_phi_operands() nounwind { 116entry: 117 br label %loop 118 119loop: 120 %i = phi i64 [ 1, %loop ], [ 0, %entry ] 121 %exitcond = icmp eq i64 %i, 1 122 br i1 %exitcond, label %return, label %loop 123 124return: 125 ret void 126} 127