1; RUN: opt < %s -analyze -basicaa -da | FileCheck %s 2 3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 4target triple = "x86_64-apple-macosx10.6.0" 5 6 7;; for (int i = 0; i < n; i++) { 8;; A[i + 2] = i; 9;; *B++ = A[i]; 10 11define void @strong0(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 12entry: 13 %cmp1 = icmp sgt i64 %n, 0 14 br i1 %cmp1, label %for.body.preheader, label %for.end 15 16; CHECK: da analyze - none! 17; CHECK: da analyze - consistent flow [2]! 18; CHECK: da analyze - confused! 19; CHECK: da analyze - none! 20; CHECK: da analyze - confused! 21; CHECK: da analyze - none! 22 23for.body.preheader: ; preds = %entry 24 br label %for.body 25 26for.body: ; preds = %for.body.preheader, %for.body 27 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 28 %B.addr.02 = phi i32* [ %incdec.ptr, %for.body ], [ %B, %for.body.preheader ] 29 %0 = add nsw i64 %indvars.iv, 2 30 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %0 31 %1 = trunc i64 %indvars.iv to i32 32 store i32 %1, i32* %arrayidx, align 4 33 %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv 34 %2 = load i32, i32* %arrayidx3, align 4 35 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.02, i64 1 36 store i32 %2, i32* %B.addr.02, align 4 37 %indvars.iv.next = add i64 %indvars.iv, 1 38 %exitcond = icmp ne i64 %indvars.iv.next, %n 39 br i1 %exitcond, label %for.body, label %for.end.loopexit 40 41for.end.loopexit: ; preds = %for.body 42 br label %for.end 43 44for.end: ; preds = %for.end.loopexit, %entry 45 ret void 46} 47 48 49;; for (long int i = 0; i < n; i++) { 50;; A[i + 2] = i; 51;; *B++ = A[i]; 52 53define void @strong1(i32* %A, i32* %B, i32 %n) nounwind uwtable ssp { 54entry: 55 %cmp1 = icmp sgt i32 %n, 0 56 br i1 %cmp1, label %for.body.preheader, label %for.end 57 58; CHECK: da analyze - none! 59; CHECK: da analyze - consistent flow [2]! 60; CHECK: da analyze - confused! 61; CHECK: da analyze - none! 62; CHECK: da analyze - confused! 63; CHECK: da analyze - none! 64 65for.body.preheader: ; preds = %entry 66 %0 = sext i32 %n to i64 67 br label %for.body 68 69for.body: ; preds = %for.body.preheader, %for.body 70 %i.03 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] 71 %B.addr.02 = phi i32* [ %incdec.ptr, %for.body ], [ %B, %for.body.preheader ] 72 %conv2 = trunc i64 %i.03 to i32 73 %add = add nsw i64 %i.03, 2 74 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 75 store i32 %conv2, i32* %arrayidx, align 4 76 %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %i.03 77 %1 = load i32, i32* %arrayidx3, align 4 78 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.02, i64 1 79 store i32 %1, i32* %B.addr.02, align 4 80 %inc = add nsw i64 %i.03, 1 81 %exitcond = icmp ne i64 %inc, %0 82 br i1 %exitcond, label %for.body, label %for.end.loopexit 83 84for.end.loopexit: ; preds = %for.body 85 br label %for.end 86 87for.end: ; preds = %for.end.loopexit, %entry 88 ret void 89} 90 91 92;; for (long unsigned i = 0; i < n; i++) { 93;; A[i + 2] = i; 94;; *B++ = A[i]; 95 96define void @strong2(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 97entry: 98 %cmp1 = icmp eq i64 %n, 0 99 br i1 %cmp1, label %for.end, label %for.body.preheader 100 101; CHECK: da analyze - none! 102; CHECK: da analyze - consistent flow [2]! 103; CHECK: da analyze - confused! 104; CHECK: da analyze - none! 105; CHECK: da analyze - confused! 106; CHECK: da analyze - none! 107 108for.body.preheader: ; preds = %entry 109 br label %for.body 110 111for.body: ; preds = %for.body.preheader, %for.body 112 %i.03 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] 113 %B.addr.02 = phi i32* [ %incdec.ptr, %for.body ], [ %B, %for.body.preheader ] 114 %conv = trunc i64 %i.03 to i32 115 %add = add i64 %i.03, 2 116 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 117 store i32 %conv, i32* %arrayidx, align 4 118 %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %i.03 119 %0 = load i32, i32* %arrayidx1, align 4 120 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.02, i64 1 121 store i32 %0, i32* %B.addr.02, align 4 122 %inc = add i64 %i.03, 1 123 %exitcond = icmp ne i64 %inc, %n 124 br i1 %exitcond, label %for.body, label %for.end.loopexit 125 126for.end.loopexit: ; preds = %for.body 127 br label %for.end 128 129for.end: ; preds = %for.end.loopexit, %entry 130 ret void 131} 132 133 134;; for (int i = 0; i < n; i++) { 135;; A[i + 2] = i; 136;; *B++ = A[i]; 137 138define void @strong3(i32* %A, i32* %B, i32 %n) nounwind uwtable ssp { 139entry: 140 %cmp1 = icmp sgt i32 %n, 0 141 br i1 %cmp1, label %for.body.preheader, label %for.end 142 143; CHECK: da analyze - none! 144; CHECK: da analyze - consistent flow [2]! 145; CHECK: da analyze - confused! 146; CHECK: da analyze - none! 147; CHECK: da analyze - confused! 148; CHECK: da analyze - none! 149 150for.body.preheader: ; preds = %entry 151 br label %for.body 152 153for.body: ; preds = %for.body.preheader, %for.body 154 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 155 %B.addr.02 = phi i32* [ %incdec.ptr, %for.body ], [ %B, %for.body.preheader ] 156 %0 = add nsw i64 %indvars.iv, 2 157 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %0 158 %1 = trunc i64 %indvars.iv to i32 159 store i32 %1, i32* %arrayidx, align 4 160 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv 161 %2 = load i32, i32* %arrayidx2, align 4 162 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.02, i64 1 163 store i32 %2, i32* %B.addr.02, align 4 164 %indvars.iv.next = add i64 %indvars.iv, 1 165 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 166 %exitcond = icmp ne i32 %lftr.wideiv, %n 167 br i1 %exitcond, label %for.body, label %for.end.loopexit 168 169for.end.loopexit: ; preds = %for.body 170 br label %for.end 171 172for.end: ; preds = %for.end.loopexit, %entry 173 ret void 174} 175 176 177;; for (long unsigned i = 0; i < 19; i++) { 178;; A[i + 19] = i; 179;; *B++ = A[i]; 180 181define void @strong4(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 182entry: 183 br label %for.body 184 185; CHECK: da analyze - none! 186; CHECK: da analyze - none! 187; CHECK: da analyze - confused! 188; CHECK: da analyze - none! 189; CHECK: da analyze - confused! 190; CHECK: da analyze - none! 191 192for.body: ; preds = %entry, %for.body 193 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 194 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 195 %conv = trunc i64 %i.02 to i32 196 %add = add i64 %i.02, 19 197 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 198 store i32 %conv, i32* %arrayidx, align 4 199 %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %i.02 200 %0 = load i32, i32* %arrayidx1, align 4 201 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 202 store i32 %0, i32* %B.addr.01, align 4 203 %inc = add i64 %i.02, 1 204 %exitcond = icmp ne i64 %inc, 19 205 br i1 %exitcond, label %for.body, label %for.end 206 207for.end: ; preds = %for.body 208 ret void 209} 210 211 212;; for (long unsigned i = 0; i < 20; i++) { 213;; A[i + 19] = i; 214;; *B++ = A[i]; 215 216define void @strong5(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 217entry: 218 br label %for.body 219 220; CHECK: da analyze - none! 221; CHECK: da analyze - consistent flow [19]! 222; CHECK: da analyze - confused! 223; CHECK: da analyze - none! 224; CHECK: da analyze - confused! 225; CHECK: da analyze - none! 226 227for.body: ; preds = %entry, %for.body 228 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 229 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 230 %conv = trunc i64 %i.02 to i32 231 %add = add i64 %i.02, 19 232 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 233 store i32 %conv, i32* %arrayidx, align 4 234 %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %i.02 235 %0 = load i32, i32* %arrayidx1, align 4 236 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 237 store i32 %0, i32* %B.addr.01, align 4 238 %inc = add i64 %i.02, 1 239 %exitcond = icmp ne i64 %inc, 20 240 br i1 %exitcond, label %for.body, label %for.end 241 242for.end: ; preds = %for.body 243 ret void 244} 245 246 247;; for (long unsigned i = 0; i < 20; i++) { 248;; A[2*i + 6] = i; 249;; *B++ = A[2*i]; 250 251define void @strong6(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 252entry: 253 br label %for.body 254 255; CHECK: da analyze - none! 256; CHECK: da analyze - consistent flow [3]! 257; CHECK: da analyze - confused! 258; CHECK: da analyze - none! 259; CHECK: da analyze - confused! 260; CHECK: da analyze - none! 261 262for.body: ; preds = %entry, %for.body 263 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 264 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 265 %conv = trunc i64 %i.02 to i32 266 %mul = shl i64 %i.02, 1 267 %add = add i64 %mul, 6 268 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 269 store i32 %conv, i32* %arrayidx, align 4 270 %mul1 = shl i64 %i.02, 1 271 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %mul1 272 %0 = load i32, i32* %arrayidx2, align 4 273 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 274 store i32 %0, i32* %B.addr.01, align 4 275 %inc = add i64 %i.02, 1 276 %exitcond = icmp ne i64 %inc, 20 277 br i1 %exitcond, label %for.body, label %for.end 278 279for.end: ; preds = %for.body 280 ret void 281} 282 283 284;; for (long unsigned i = 0; i < 20; i++) { 285;; A[2*i + 7] = i; 286;; *B++ = A[2*i]; 287 288define void @strong7(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 289entry: 290 br label %for.body 291 292; CHECK: da analyze - none! 293; CHECK: da analyze - none! 294; CHECK: da analyze - confused! 295; CHECK: da analyze - none! 296; CHECK: da analyze - confused! 297; CHECK: da analyze - none! 298 299for.body: ; preds = %entry, %for.body 300 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 301 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 302 %conv = trunc i64 %i.02 to i32 303 %mul = shl i64 %i.02, 1 304 %add = add i64 %mul, 7 305 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 306 store i32 %conv, i32* %arrayidx, align 4 307 %mul1 = shl i64 %i.02, 1 308 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %mul1 309 %0 = load i32, i32* %arrayidx2, align 4 310 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 311 store i32 %0, i32* %B.addr.01, align 4 312 %inc = add i64 %i.02, 1 313 %exitcond = icmp ne i64 %inc, 20 314 br i1 %exitcond, label %for.body, label %for.end 315 316for.end: ; preds = %for.body 317 ret void 318} 319 320 321;; for (long unsigned i = 0; i < 20; i++) { 322;; A[i + n] = i; 323;; *B++ = A[i]; 324 325define void @strong8(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 326entry: 327 br label %for.body 328 329; CHECK: da analyze - none! 330; CHECK: da analyze - flow [*|<]! 331; CHECK: da analyze - confused! 332; CHECK: da analyze - none! 333; CHECK: da analyze - confused! 334; CHECK: da analyze - none! 335 336for.body: ; preds = %entry, %for.body 337 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 338 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 339 %conv = trunc i64 %i.02 to i32 340 %add = add i64 %i.02, %n 341 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 342 store i32 %conv, i32* %arrayidx, align 4 343 %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %i.02 344 %0 = load i32, i32* %arrayidx1, align 4 345 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 346 store i32 %0, i32* %B.addr.01, align 4 347 %inc = add i64 %i.02, 1 348 %exitcond = icmp ne i64 %inc, 20 349 br i1 %exitcond, label %for.body, label %for.end 350 351for.end: ; preds = %for.body 352 ret void 353} 354 355 356;; for (long unsigned i = 0; i < n; i++) { 357;; A[i + n] = i; 358;; *B++ = A[i + 2*n]; 359 360define void @strong9(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 361entry: 362 %cmp1 = icmp eq i64 %n, 0 363 br i1 %cmp1, label %for.end, label %for.body.preheader 364 365; CHECK: da analyze - none! 366; CHECK: da analyze - none! 367; CHECK: da analyze - confused! 368; CHECK: da analyze - none! 369; CHECK: da analyze - confused! 370; CHECK: da analyze - none! 371 372for.body.preheader: ; preds = %entry 373 br label %for.body 374 375for.body: ; preds = %for.body.preheader, %for.body 376 %i.03 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] 377 %B.addr.02 = phi i32* [ %incdec.ptr, %for.body ], [ %B, %for.body.preheader ] 378 %conv = trunc i64 %i.03 to i32 379 %add = add i64 %i.03, %n 380 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 381 store i32 %conv, i32* %arrayidx, align 4 382 %mul = shl i64 %n, 1 383 %add1 = add i64 %i.03, %mul 384 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %add1 385 %0 = load i32, i32* %arrayidx2, align 4 386 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.02, i64 1 387 store i32 %0, i32* %B.addr.02, align 4 388 %inc = add i64 %i.03, 1 389 %exitcond = icmp ne i64 %inc, %n 390 br i1 %exitcond, label %for.body, label %for.end.loopexit 391 392for.end.loopexit: ; preds = %for.body 393 br label %for.end 394 395for.end: ; preds = %for.end.loopexit, %entry 396 ret void 397} 398 399 400;; for (long unsigned i = 0; i < 1000; i++) { 401;; A[n*i + 5] = i; 402;; *B++ = A[n*i + 5]; 403 404define void @strong10(i32* %A, i32* %B, i64 %n) nounwind uwtable ssp { 405entry: 406 br label %for.body 407 408; CHECK: da analyze - none! 409; CHECK: da analyze - consistent flow [0|<]! 410; CHECK: da analyze - confused! 411; CHECK: da analyze - none! 412; CHECK: da analyze - confused! 413; CHECK: da analyze - none! 414 415for.body: ; preds = %entry, %for.body 416 %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 417 %B.addr.01 = phi i32* [ %B, %entry ], [ %incdec.ptr, %for.body ] 418 %conv = trunc i64 %i.02 to i32 419 %mul = mul i64 %i.02, %n 420 %add = add i64 %mul, 5 421 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add 422 store i32 %conv, i32* %arrayidx, align 4 423 %mul1 = mul i64 %i.02, %n 424 %add2 = add i64 %mul1, 5 425 %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %add2 426 %0 = load i32, i32* %arrayidx3, align 4 427 %incdec.ptr = getelementptr inbounds i32, i32* %B.addr.01, i64 1 428 store i32 %0, i32* %B.addr.01, align 4 429 %inc = add i64 %i.02, 1 430 %exitcond = icmp ne i64 %inc, 1000 431 br i1 %exitcond, label %for.body, label %for.end 432 433for.end: ; preds = %for.body 434 ret void 435} 436