1*9880d681SAndroid Build Coastguard Worker; RUN: opt -analyze -scalar-evolution -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; Every combination of 4*9880d681SAndroid Build Coastguard Worker; - starting at 0, 1, or %x 5*9880d681SAndroid Build Coastguard Worker; - steping by 1 or 2 6*9880d681SAndroid Build Coastguard Worker; - stopping at %n or %n*2 7*9880d681SAndroid Build Coastguard Worker; - using nsw, or not 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker; Some of these represent missed opportunities. 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @foo 12*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + %n) 13*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 6 14*9880d681SAndroid Build Coastguard Workerdefine void @foo(i4 %n) { 15*9880d681SAndroid Build Coastguard Workerentry: 16*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 17*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 18*9880d681SAndroid Build Coastguard Workerloop: 19*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 20*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 21*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 22*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 23*9880d681SAndroid Build Coastguard Workerexit: 24*9880d681SAndroid Build Coastguard Worker ret void 25*9880d681SAndroid Build Coastguard Worker} 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @step2 28*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable backedge-taken count. 29*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable max backedge-taken count. 30*9880d681SAndroid Build Coastguard Workerdefine void @step2(i4 %n) { 31*9880d681SAndroid Build Coastguard Workerentry: 32*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 33*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 34*9880d681SAndroid Build Coastguard Workerloop: 35*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 36*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 37*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 38*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 39*9880d681SAndroid Build Coastguard Workerexit: 40*9880d681SAndroid Build Coastguard Worker ret void 41*9880d681SAndroid Build Coastguard Worker} 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @start1 44*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-2 + (2 smax %n)) 45*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 5 46*9880d681SAndroid Build Coastguard Workerdefine void @start1(i4 %n) { 47*9880d681SAndroid Build Coastguard Workerentry: 48*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 49*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 50*9880d681SAndroid Build Coastguard Workerloop: 51*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 52*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 53*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 54*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 55*9880d681SAndroid Build Coastguard Workerexit: 56*9880d681SAndroid Build Coastguard Worker ret void 57*9880d681SAndroid Build Coastguard Worker} 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @start1_step2 60*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable backedge-taken count. 61*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable max backedge-taken count. 62*9880d681SAndroid Build Coastguard Workerdefine void @start1_step2(i4 %n) { 63*9880d681SAndroid Build Coastguard Workerentry: 64*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 65*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 66*9880d681SAndroid Build Coastguard Workerloop: 67*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 68*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 69*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 70*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 71*9880d681SAndroid Build Coastguard Workerexit: 72*9880d681SAndroid Build Coastguard Worker ret void 73*9880d681SAndroid Build Coastguard Worker} 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @startx 76*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) 77*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is -1 78*9880d681SAndroid Build Coastguard Workerdefine void @startx(i4 %n, i4 %x) { 79*9880d681SAndroid Build Coastguard Workerentry: 80*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 81*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 82*9880d681SAndroid Build Coastguard Workerloop: 83*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 84*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 85*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 86*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 87*9880d681SAndroid Build Coastguard Workerexit: 88*9880d681SAndroid Build Coastguard Worker ret void 89*9880d681SAndroid Build Coastguard Worker} 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @startx_step2 92*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable backedge-taken count. 93*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: Unpredictable max backedge-taken count. 94*9880d681SAndroid Build Coastguard Workerdefine void @startx_step2(i4 %n, i4 %x) { 95*9880d681SAndroid Build Coastguard Workerentry: 96*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 97*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 98*9880d681SAndroid Build Coastguard Workerloop: 99*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 100*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 101*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 102*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 103*9880d681SAndroid Build Coastguard Workerexit: 104*9880d681SAndroid Build Coastguard Worker ret void 105*9880d681SAndroid Build Coastguard Worker} 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw 108*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + %n) 109*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 6 110*9880d681SAndroid Build Coastguard Workerdefine void @nsw(i4 %n) { 111*9880d681SAndroid Build Coastguard Workerentry: 112*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 113*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 114*9880d681SAndroid Build Coastguard Workerloop: 115*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 116*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 117*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 118*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 119*9880d681SAndroid Build Coastguard Workerexit: 120*9880d681SAndroid Build Coastguard Worker ret void 121*9880d681SAndroid Build Coastguard Worker} 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Worker; If %n is INT4_MAX, %i.next will wrap. The nsw bit says that the 124*9880d681SAndroid Build Coastguard Worker; result is undefined. Therefore, after the loop's second iteration, 125*9880d681SAndroid Build Coastguard Worker; we are free to assume that the loop exits. This is valid because: 126*9880d681SAndroid Build Coastguard Worker; (a) %i.next is a poison value after the second iteration, which can 127*9880d681SAndroid Build Coastguard Worker; also be considered an undef value. 128*9880d681SAndroid Build Coastguard Worker; (b) the return instruction enacts a side effect that is control 129*9880d681SAndroid Build Coastguard Worker; dependent on the poison value. 130*9880d681SAndroid Build Coastguard Worker; 131*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: nsw_step2 132*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw_step2 133*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + %n) /u 2) 134*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 135*9880d681SAndroid Build Coastguard Workerdefine void @nsw_step2(i4 %n) { 136*9880d681SAndroid Build Coastguard Workerentry: 137*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 138*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 139*9880d681SAndroid Build Coastguard Workerloop: 140*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 141*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 142*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 143*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 144*9880d681SAndroid Build Coastguard Workerexit: 145*9880d681SAndroid Build Coastguard Worker ret void 146*9880d681SAndroid Build Coastguard Worker} 147*9880d681SAndroid Build Coastguard Worker 148*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: nsw_start1 149*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw_start1 150*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-2 + (2 smax %n)) 151*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 5 152*9880d681SAndroid Build Coastguard Workerdefine void @nsw_start1(i4 %n) { 153*9880d681SAndroid Build Coastguard Workerentry: 154*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 155*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 156*9880d681SAndroid Build Coastguard Workerloop: 157*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 158*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 159*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 160*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 161*9880d681SAndroid Build Coastguard Workerexit: 162*9880d681SAndroid Build Coastguard Worker ret void 163*9880d681SAndroid Build Coastguard Worker} 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw_start1_step2 166*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-2 + (3 smax %n)) /u 2) 167*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 168*9880d681SAndroid Build Coastguard Workerdefine void @nsw_start1_step2(i4 %n) { 169*9880d681SAndroid Build Coastguard Workerentry: 170*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 171*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 172*9880d681SAndroid Build Coastguard Workerloop: 173*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 174*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 175*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 176*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 177*9880d681SAndroid Build Coastguard Workerexit: 178*9880d681SAndroid Build Coastguard Worker ret void 179*9880d681SAndroid Build Coastguard Worker} 180*9880d681SAndroid Build Coastguard Worker 181*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw_startx 182*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) 183*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is -1 184*9880d681SAndroid Build Coastguard Workerdefine void @nsw_startx(i4 %n, i4 %x) { 185*9880d681SAndroid Build Coastguard Workerentry: 186*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 187*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 188*9880d681SAndroid Build Coastguard Workerloop: 189*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 190*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 191*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 192*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 193*9880d681SAndroid Build Coastguard Workerexit: 194*9880d681SAndroid Build Coastguard Worker ret void 195*9880d681SAndroid Build Coastguard Worker} 196*9880d681SAndroid Build Coastguard Worker 197*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @nsw_startx_step2 198*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2) 199*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 7 200*9880d681SAndroid Build Coastguard Workerdefine void @nsw_startx_step2(i4 %n, i4 %x) { 201*9880d681SAndroid Build Coastguard Workerentry: 202*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %n, 0 203*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 204*9880d681SAndroid Build Coastguard Workerloop: 205*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 206*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 207*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %n 208*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 209*9880d681SAndroid Build Coastguard Workerexit: 210*9880d681SAndroid Build Coastguard Worker ret void 211*9880d681SAndroid Build Coastguard Worker} 212*9880d681SAndroid Build Coastguard Worker 213*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even 214*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (2 * %n)) 215*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 5 216*9880d681SAndroid Build Coastguard Workerdefine void @even(i4 %n) { 217*9880d681SAndroid Build Coastguard Workerentry: 218*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 219*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 220*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 221*9880d681SAndroid Build Coastguard Workerloop: 222*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 223*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 224*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 225*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 226*9880d681SAndroid Build Coastguard Workerexit: 227*9880d681SAndroid Build Coastguard Worker ret void 228*9880d681SAndroid Build Coastguard Worker} 229*9880d681SAndroid Build Coastguard Worker 230*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_step2 231*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + (2 * %n)) /u 2) 232*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 233*9880d681SAndroid Build Coastguard Workerdefine void @even_step2(i4 %n) { 234*9880d681SAndroid Build Coastguard Workerentry: 235*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 236*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 237*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 238*9880d681SAndroid Build Coastguard Workerloop: 239*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 240*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 241*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 242*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 243*9880d681SAndroid Build Coastguard Workerexit: 244*9880d681SAndroid Build Coastguard Worker ret void 245*9880d681SAndroid Build Coastguard Worker} 246*9880d681SAndroid Build Coastguard Worker 247*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_start1 248*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-2 + (2 smax (2 * %n))) 249*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 4 250*9880d681SAndroid Build Coastguard Workerdefine void @even_start1(i4 %n) { 251*9880d681SAndroid Build Coastguard Workerentry: 252*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 253*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 254*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 255*9880d681SAndroid Build Coastguard Workerloop: 256*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 257*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 258*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 259*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 260*9880d681SAndroid Build Coastguard Workerexit: 261*9880d681SAndroid Build Coastguard Worker ret void 262*9880d681SAndroid Build Coastguard Worker} 263*9880d681SAndroid Build Coastguard Worker 264*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_start1_step2 265*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-2 + (3 smax (2 * %n))) /u 2) 266*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 267*9880d681SAndroid Build Coastguard Workerdefine void @even_start1_step2(i4 %n) { 268*9880d681SAndroid Build Coastguard Workerentry: 269*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 270*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 271*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 272*9880d681SAndroid Build Coastguard Workerloop: 273*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 274*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 275*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 276*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 277*9880d681SAndroid Build Coastguard Workerexit: 278*9880d681SAndroid Build Coastguard Worker ret void 279*9880d681SAndroid Build Coastguard Worker} 280*9880d681SAndroid Build Coastguard Worker 281*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_startx 282*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) 283*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is -2 284*9880d681SAndroid Build Coastguard Workerdefine void @even_startx(i4 %n, i4 %x) { 285*9880d681SAndroid Build Coastguard Workerentry: 286*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 287*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 288*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 289*9880d681SAndroid Build Coastguard Workerloop: 290*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 291*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 1 292*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 293*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 294*9880d681SAndroid Build Coastguard Workerexit: 295*9880d681SAndroid Build Coastguard Worker ret void 296*9880d681SAndroid Build Coastguard Worker} 297*9880d681SAndroid Build Coastguard Worker 298*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_startx_step2 299*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) 300*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 7 301*9880d681SAndroid Build Coastguard Workerdefine void @even_startx_step2(i4 %n, i4 %x) { 302*9880d681SAndroid Build Coastguard Workerentry: 303*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 304*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 305*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 306*9880d681SAndroid Build Coastguard Workerloop: 307*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 308*9880d681SAndroid Build Coastguard Worker %i.next = add i4 %i, 2 309*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 310*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 311*9880d681SAndroid Build Coastguard Workerexit: 312*9880d681SAndroid Build Coastguard Worker ret void 313*9880d681SAndroid Build Coastguard Worker} 314*9880d681SAndroid Build Coastguard Worker 315*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw 316*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (2 * %n)) 317*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 5 318*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw(i4 %n) { 319*9880d681SAndroid Build Coastguard Workerentry: 320*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 321*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 322*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 323*9880d681SAndroid Build Coastguard Workerloop: 324*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 325*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 326*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 327*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 328*9880d681SAndroid Build Coastguard Workerexit: 329*9880d681SAndroid Build Coastguard Worker ret void 330*9880d681SAndroid Build Coastguard Worker} 331*9880d681SAndroid Build Coastguard Worker 332*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw_step2 333*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + (2 * %n)) /u 2) 334*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 335*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw_step2(i4 %n) { 336*9880d681SAndroid Build Coastguard Workerentry: 337*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 338*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 339*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 340*9880d681SAndroid Build Coastguard Workerloop: 341*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 0, %entry ], [ %i.next, %loop ] 342*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 343*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 344*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 345*9880d681SAndroid Build Coastguard Workerexit: 346*9880d681SAndroid Build Coastguard Worker ret void 347*9880d681SAndroid Build Coastguard Worker} 348*9880d681SAndroid Build Coastguard Worker 349*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw_start1 350*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-2 + (2 smax (2 * %n))) 351*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 4 352*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw_start1(i4 %n) { 353*9880d681SAndroid Build Coastguard Workerentry: 354*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 355*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 356*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 357*9880d681SAndroid Build Coastguard Workerloop: 358*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 359*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 360*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 361*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 362*9880d681SAndroid Build Coastguard Workerexit: 363*9880d681SAndroid Build Coastguard Worker ret void 364*9880d681SAndroid Build Coastguard Worker} 365*9880d681SAndroid Build Coastguard Worker 366*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw_start1_step2 367*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-2 + (3 smax (2 * %n))) /u 2) 368*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 2 369*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw_start1_step2(i4 %n) { 370*9880d681SAndroid Build Coastguard Workerentry: 371*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 372*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 373*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 374*9880d681SAndroid Build Coastguard Workerloop: 375*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ 1, %entry ], [ %i.next, %loop ] 376*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 377*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 378*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 379*9880d681SAndroid Build Coastguard Workerexit: 380*9880d681SAndroid Build Coastguard Worker ret void 381*9880d681SAndroid Build Coastguard Worker} 382*9880d681SAndroid Build Coastguard Worker 383*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw_startx 384*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) 385*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is -2 386*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw_startx(i4 %n, i4 %x) { 387*9880d681SAndroid Build Coastguard Workerentry: 388*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 389*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 390*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 391*9880d681SAndroid Build Coastguard Workerloop: 392*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 393*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 1 394*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 395*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 396*9880d681SAndroid Build Coastguard Workerexit: 397*9880d681SAndroid Build Coastguard Worker ret void 398*9880d681SAndroid Build Coastguard Worker} 399*9880d681SAndroid Build Coastguard Worker 400*9880d681SAndroid Build Coastguard Worker; CHECK: Determining loop execution counts for: @even_nsw_startx_step2 401*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) 402*9880d681SAndroid Build Coastguard Worker; CHECK: Loop %loop: max backedge-taken count is 7 403*9880d681SAndroid Build Coastguard Workerdefine void @even_nsw_startx_step2(i4 %n, i4 %x) { 404*9880d681SAndroid Build Coastguard Workerentry: 405*9880d681SAndroid Build Coastguard Worker %m = shl i4 %n, 1 406*9880d681SAndroid Build Coastguard Worker %s = icmp sgt i4 %m, 0 407*9880d681SAndroid Build Coastguard Worker br i1 %s, label %loop, label %exit 408*9880d681SAndroid Build Coastguard Workerloop: 409*9880d681SAndroid Build Coastguard Worker %i = phi i4 [ %x, %entry ], [ %i.next, %loop ] 410*9880d681SAndroid Build Coastguard Worker %i.next = add nsw i4 %i, 2 411*9880d681SAndroid Build Coastguard Worker %t = icmp slt i4 %i.next, %m 412*9880d681SAndroid Build Coastguard Worker br i1 %t, label %loop, label %exit 413*9880d681SAndroid Build Coastguard Workerexit: 414*9880d681SAndroid Build Coastguard Worker ret void 415*9880d681SAndroid Build Coastguard Worker} 416