1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5 2; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s 3 4define dso_local void @simple(i32 noundef %n) local_unnamed_addr { 5; CHECK-LABEL: 'simple' 6; CHECK-NEXT: Classifying expressions for: @simple 7; CHECK-NEXT: %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ] 8; CHECK-NEXT: --> {%n,+,-4}<nsw><%while.body> U: full-set S: full-set Exits: ((-4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nsw> + %n) LoopDispositions: { %while.body: Computable } 9; CHECK-NEXT: %left.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ] 10; CHECK-NEXT: --> {0,+,4}<nuw><nsw><%while.body> U: [0,2147483641) S: [0,2147483641) Exits: (4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nuw> LoopDispositions: { %while.body: Computable } 11; CHECK-NEXT: %inc = add nuw nsw i32 %left.05, 4 12; CHECK-NEXT: --> {4,+,4}<nuw><nsw><%while.body> U: [4,2147483645) S: [4,2147483645) Exits: (4 + (4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nuw>)<nuw> LoopDispositions: { %while.body: Computable } 13; CHECK-NEXT: %dec = add nsw i32 %right.06, -4 14; CHECK-NEXT: --> {(-4 + %n),+,-4}<nsw><%while.body> U: full-set S: full-set Exits: (-4 + (-4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nsw> + %n) LoopDispositions: { %while.body: Computable } 15; CHECK-NEXT: Determining loop execution counts for: @simple 16; CHECK-NEXT: Loop %while.body: backedge-taken count is (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)) 17; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 536870910 18; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)) 19; CHECK-NEXT: Loop %while.body: Trip multiple is 1 20; 21entry: 22 %cmp4 = icmp sgt i32 %n, 0 23 br i1 %cmp4, label %while.body, label %while.end 24 25while.body: 26 %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ] 27 %left.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ] 28 %inc = add nuw nsw i32 %left.05, 4 29 %dec = add nsw i32 %right.06, -4 30 %cmp = icmp slt i32 %inc, %dec 31 br i1 %cmp, label %while.body, label %while.end 32 33while.end: 34 ret void 35} 36 37; Cannot find backedge-count because subtraction of strides is wrapping. 38define dso_local void @stride_overflow(i32 noundef %n) local_unnamed_addr { 39; CHECK-LABEL: 'stride_overflow' 40; CHECK-NEXT: Classifying expressions for: @stride_overflow 41; CHECK-NEXT: %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ] 42; CHECK-NEXT: --> {%n,+,-1}<nsw><%while.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 43; CHECK-NEXT: %left.05 = phi i32 [ %inc, %while.body ], [ 2147483647, %entry ] 44; CHECK-NEXT: --> {2147483647,+,2147483647}<nuw><nsw><%while.body> U: [2147483647,-2147483648) S: [2147483647,-2147483648) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 45; CHECK-NEXT: %inc = add nuw nsw i32 %left.05, 2147483647 46; CHECK-NEXT: --> {-2,+,2147483647}<nuw><nsw><%while.body> U: [-2,-1) S: [-2,0) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 47; CHECK-NEXT: %dec = add nsw i32 %right.06, -1 48; CHECK-NEXT: --> {(-1 + %n),+,-1}<nsw><%while.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 49; CHECK-NEXT: Determining loop execution counts for: @stride_overflow 50; CHECK-NEXT: Loop %while.body: Unpredictable backedge-taken count. 51; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 1 52; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is i32 1 53; 54entry: 55 %cmp4 = icmp sgt i32 %n, 0 56 br i1 %cmp4, label %while.body, label %while.end 57 58while.body: 59 %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ] 60 %left.05 = phi i32 [ %inc, %while.body ], [ 2147483647, %entry ] 61 %inc = add nuw nsw i32 %left.05, 2147483647 62 %dec = add nsw i32 %right.06, -1 63 %cmp = icmp slt i32 %inc, %dec 64 br i1 %cmp, label %while.body, label %while.end 65 66while.end: 67 ret void 68} 69 70; Cannot find backedge-count because %conv110 is wrapping 71define dso_local void @rhs_wrapping() local_unnamed_addr { 72; CHECK-LABEL: 'rhs_wrapping' 73; CHECK-NEXT: Classifying expressions for: @rhs_wrapping 74; CHECK-NEXT: %a = alloca i8, align 1 75; CHECK-NEXT: --> %a U: full-set S: full-set 76; CHECK-NEXT: %conv110 = phi i32 [ 0, %entry ], [ %sext8, %while.body ] 77; CHECK-NEXT: --> {0,+,-1090519040}<%while.body> U: [0,-16777215) S: [-2147483648,2130706433) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 78; CHECK-NEXT: %conv9 = phi i32 [ -2147483648, %entry ], [ %sext, %while.body ] 79; CHECK-NEXT: --> {-2147483648,+,16777216}<nsw><%while.body> U: [0,-16777215) S: [-2147483648,2113929217) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 80; CHECK-NEXT: %sext = add nsw i32 %conv9, 16777216 81; CHECK-NEXT: --> {-2130706432,+,16777216}<nsw><%while.body> U: [0,-16777215) S: [-2130706432,2130706433) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 82; CHECK-NEXT: %sext8 = add i32 %conv110, -1090519040 83; CHECK-NEXT: --> {-1090519040,+,-1090519040}<%while.body> U: [0,-16777215) S: [-2147483648,2130706433) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable } 84; CHECK-NEXT: Determining loop execution counts for: @rhs_wrapping 85; CHECK-NEXT: Loop %while.body: Unpredictable backedge-taken count. 86; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 254 87; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is i32 254 88; 89entry: 90 %a = alloca i8, align 1 91 br label %while.body 92 93while.body: 94 %conv110 = phi i32 [ 0, %entry ], [ %sext8, %while.body ] 95 %conv9 = phi i32 [ -2147483648, %entry ], [ %sext, %while.body ] 96 %sext = add nsw i32 %conv9, 16777216 97 %sext8 = add i32 %conv110, -1090519040 98 %cmp = icmp slt i32 %sext, %sext8 99 br i1 %cmp, label %while.body, label %while.end 100 101while.end: 102 ret void 103} 104 105; abs(left_stride) != abs(right_stride) 106define dso_local void @simple2() local_unnamed_addr { 107; CHECK-LABEL: 'simple2' 108; CHECK-NEXT: Classifying expressions for: @simple2 109; CHECK-NEXT: %right.08 = phi i32 [ 50, %entry ], [ %add2, %while.body ] 110; CHECK-NEXT: --> {50,+,-5}<nsw><%while.body> U: [25,51) S: [25,51) Exits: 25 LoopDispositions: { %while.body: Computable } 111; CHECK-NEXT: %left.07 = phi i32 [ 0, %entry ], [ %add, %while.body ] 112; CHECK-NEXT: --> {0,+,4}<nuw><nsw><%while.body> U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %while.body: Computable } 113; CHECK-NEXT: %add = add nuw nsw i32 %left.07, 4 114; CHECK-NEXT: --> {4,+,4}<nuw><nsw><%while.body> U: [4,25) S: [4,25) Exits: 24 LoopDispositions: { %while.body: Computable } 115; CHECK-NEXT: %add2 = add nsw i32 %right.08, -5 116; CHECK-NEXT: --> {45,+,-5}<nsw><%while.body> U: [20,46) S: [20,46) Exits: 20 LoopDispositions: { %while.body: Computable } 117; CHECK-NEXT: Determining loop execution counts for: @simple2 118; CHECK-NEXT: Loop %while.body: backedge-taken count is i32 5 119; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 5 120; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is i32 5 121; CHECK-NEXT: Loop %while.body: Trip multiple is 6 122; 123entry: 124 br label %while.body 125 126while.body: 127 %right.08 = phi i32 [ 50, %entry ], [ %add2, %while.body ] 128 %left.07 = phi i32 [ 0, %entry ], [ %add, %while.body ] 129 %add = add nuw nsw i32 %left.07, 4 130 %add2 = add nsw i32 %right.08, -5 131 %cmp = icmp slt i32 %add, %add2 132 br i1 %cmp, label %while.body, label %while.end 133 134while.end: 135 ret void 136} 137