1; RUN: opt -loop-reduce -disable-output -debug-only=loop-reduce < %s 2>&1 | FileCheck %s 2; REQUIRES: asserts 3; 4; PR13361: LSR + SCEV "hangs" on reasonably sized test with sequence of loops 5; 6; Without limits on CollectSubexpr, we have thousands of formulae for 7; the use that crosses loops. With limits we have five. 8; CHECK: LSR on loop %bb221: 9; CHECK: After generating reuse formulae: 10; CHECK: LSR is examining the following uses: 11; CHECK: LSR Use: Kind=Special 12; CHECK: {{.*reg\(\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{}} 13; CHECK: {{.*reg\(\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{}} 14; CHECK: {{.*reg\(\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{}} 15; CHECK: {{.*reg\(\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{}} 16; CHECK: {{.*reg\(\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{}} 17; CHECK-NOT:reg 18; CHECK: Filtering for use 19 20; Provide legal integer types. 21target datalayout = "n8:16:32:64" 22 23 24%struct.snork = type { %struct.fuga, i32, i32, i32, i32, i32, i32 } 25%struct.fuga = type { %struct.gork, i64 } 26%struct.gork = type { i8*, i32, i32, %struct.noot* } 27%struct.noot = type opaque 28%struct.jim = type { [5120 x i8], i32, i32, [2048 x i8], i32, [256 x i8] } 29 30@global = external global %struct.snork, align 8 31@global1 = external hidden unnamed_addr constant [52 x i8], align 1 32@global2 = external hidden unnamed_addr constant [18 x i8], align 1 33@global3 = external hidden global %struct.jim, align 32 34@global4 = external hidden unnamed_addr constant [40 x i8], align 1 35 36declare void @snork(...) nounwind 37 38declare fastcc void @blarg() nounwind uwtable readonly 39 40define hidden fastcc void @boogle() nounwind uwtable { 41bb: 42 %tmp = trunc i64 0 to i32 43 %tmp1 = icmp slt i32 %tmp, 2047 44 %tmp2 = add i32 0, -1 45 %tmp3 = icmp ult i32 %tmp2, 255 46 %tmp4 = and i1 %tmp1, %tmp3 47 br i1 %tmp4, label %bb6, label %bb5 48 49bb5: ; preds = %bb 50 tail call void (...) @snork(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @global1, i64 0, i64 0), i32 2021) nounwind 51 tail call void (...) @snork(i8* getelementptr inbounds (%struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 1), i32 -2146631418) nounwind 52 unreachable 53 54bb6: ; preds = %bb 55 tail call void @zot(i8* getelementptr inbounds (%struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 0), i8* getelementptr inbounds (%struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 1), i64 undef, i32 1, i1 false) nounwind 56 %tmp7 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 undef 57 store i8 0, i8* %tmp7, align 1 58 %tmp8 = add nsw i32 0, 1 59 %tmp9 = sext i32 %tmp8 to i64 60 %tmp10 = add i64 %tmp9, 1 61 %tmp11 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 %tmp10 62 %tmp12 = sub i64 2047, %tmp9 63 %tmp13 = icmp eq i32 undef, 1 64 br i1 %tmp13, label %bb14, label %bb15 65 66bb14: ; preds = %bb6 67 tail call fastcc void @blarg() 68 unreachable 69 70bb15: ; preds = %bb6 71 %tmp16 = trunc i64 %tmp12 to i32 72 br label %bb17 73 74bb17: ; preds = %bb26, %bb15 75 %tmp18 = phi i64 [ %tmp28, %bb26 ], [ 0, %bb15 ] 76 %tmp19 = phi i32 [ %tmp29, %bb26 ], [ 0, %bb15 ] 77 %tmp20 = trunc i64 %tmp18 to i32 78 %tmp21 = icmp slt i32 %tmp20, %tmp16 79 br i1 %tmp21, label %bb22, label %bb32 80 81bb22: ; preds = %bb17 82 %tmp23 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 0 83 %tmp24 = load i8, i8* %tmp23, align 1 84 %tmp25 = icmp eq i8 %tmp24, 58 85 br i1 %tmp25, label %bb30, label %bb26 86 87bb26: ; preds = %bb22 88 %tmp27 = icmp eq i8 %tmp24, 0 89 %tmp28 = add i64 %tmp18, 1 90 %tmp29 = add nsw i32 %tmp19, 1 91 br i1 %tmp27, label %bb32, label %bb17 92 93bb30: ; preds = %bb22 94 %tmp31 = icmp ult i32 undef, 255 95 br i1 %tmp31, label %bb33, label %bb32 96 97bb32: ; preds = %bb30, %bb26, %bb17 98 tail call void (...) @snork(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @global1, i64 0, i64 0), i32 2038) nounwind 99 tail call void (...) @snork(i8* %tmp11, i32 -2146631418) nounwind 100 unreachable 101 102bb33: ; preds = %bb30 103 tail call void @zot(i8* getelementptr inbounds (%struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 0), i8* %tmp11, i64 undef, i32 1, i1 false) nounwind 104 %tmp34 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 undef 105 store i8 0, i8* %tmp34, align 1 106 %tmp35 = add nsw i32 %tmp19, 1 107 %tmp36 = sext i32 %tmp35 to i64 108 %tmp37 = add i64 %tmp36, %tmp10 109 %tmp38 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 %tmp37 110 %tmp39 = sub i64 %tmp12, %tmp36 111 br i1 false, label %bb40, label %bb41 112 113bb40: ; preds = %bb33 114 br label %bb41 115 116bb41: ; preds = %bb40, %bb33 117 %tmp42 = trunc i64 %tmp39 to i32 118 br label %bb43 119 120bb43: ; preds = %bb52, %bb41 121 %tmp44 = phi i64 [ %tmp53, %bb52 ], [ 0, %bb41 ] 122 %tmp45 = phi i32 [ %tmp54, %bb52 ], [ 0, %bb41 ] 123 %tmp46 = trunc i64 %tmp44 to i32 124 %tmp47 = icmp slt i32 %tmp46, %tmp42 125 br i1 %tmp47, label %bb48, label %bb58 126 127bb48: ; preds = %bb43 128 %tmp49 = add i64 %tmp44, %tmp37 129 %tmp50 = load i8, i8* undef, align 1 130 %tmp51 = icmp eq i8 %tmp50, 58 131 br i1 %tmp51, label %bb55, label %bb52 132 133bb52: ; preds = %bb48 134 %tmp53 = add i64 %tmp44, 1 135 %tmp54 = add nsw i32 %tmp45, 1 136 br i1 undef, label %bb58, label %bb43 137 138bb55: ; preds = %bb48 139 %tmp56 = add i32 %tmp45, -1 140 %tmp57 = icmp ult i32 %tmp56, 255 141 br i1 %tmp57, label %bb59, label %bb58 142 143bb58: ; preds = %bb55, %bb52, %bb43 144 tail call void (...) @snork(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @global1, i64 0, i64 0), i32 2055) nounwind 145 tail call void (...) @snork(i8* %tmp38, i32 -2146631418) nounwind 146 br label %bb247 147 148bb59: ; preds = %bb55 149 %tmp60 = sext i32 %tmp45 to i64 150 tail call void @zot(i8* getelementptr inbounds (%struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 0), i8* %tmp38, i64 %tmp60, i32 1, i1 false) nounwind 151 %tmp61 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 5, i64 %tmp60 152 store i8 0, i8* %tmp61, align 1 153 %tmp62 = add nsw i32 %tmp45, 1 154 %tmp63 = sext i32 %tmp62 to i64 155 %tmp64 = add i64 %tmp63, %tmp37 156 %tmp65 = sub i64 %tmp39, %tmp63 157 %tmp66 = icmp eq i32 undef, 2 158 br i1 %tmp66, label %bb67, label %bb68 159 160bb67: ; preds = %bb59 161 tail call fastcc void @blarg() 162 unreachable 163 164bb68: ; preds = %bb59 165 switch i32 undef, label %bb71 [ 166 i32 0, label %bb74 167 i32 -1, label %bb69 168 ] 169 170bb69: ; preds = %bb68 171 tail call void (...) @snork(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @global1, i64 0, i64 0), i32 2071) nounwind 172 %tmp70 = load i32, i32* getelementptr inbounds (%struct.snork, %struct.snork* @global, i64 0, i32 2), align 4 173 unreachable 174 175bb71: ; preds = %bb68 176 %tmp72 = load i32, i32* getelementptr inbounds (%struct.snork, %struct.snork* @global, i64 0, i32 4), align 4 177 %tmp73 = icmp eq i32 undef, 0 178 br i1 %tmp73, label %bb247, label %bb74 179 180bb74: ; preds = %bb71, %bb68 181 %tmp75 = trunc i64 %tmp65 to i32 182 br label %bb76 183 184bb76: ; preds = %bb82, %bb74 185 %tmp77 = phi i64 [ %tmp84, %bb82 ], [ 0, %bb74 ] 186 %tmp78 = phi i32 [ %tmp85, %bb82 ], [ 0, %bb74 ] 187 %tmp79 = trunc i64 %tmp77 to i32 188 %tmp80 = icmp slt i32 %tmp79, %tmp75 189 br i1 %tmp80, label %bb81, label %bb87 190 191bb81: ; preds = %bb76 192 br i1 false, label %bb86, label %bb82 193 194bb82: ; preds = %bb81 195 %tmp83 = icmp eq i8 0, 0 196 %tmp84 = add i64 %tmp77, 1 197 %tmp85 = add nsw i32 %tmp78, 1 198 br i1 %tmp83, label %bb87, label %bb76 199 200bb86: ; preds = %bb81 201 br i1 undef, label %bb88, label %bb87 202 203bb87: ; preds = %bb86, %bb82, %bb76 204 unreachable 205 206bb88: ; preds = %bb86 207 %tmp89 = add nsw i32 %tmp78, 1 208 %tmp90 = sext i32 %tmp89 to i64 209 %tmp91 = add i64 %tmp90, %tmp64 210 %tmp92 = sub i64 %tmp65, %tmp90 211 br i1 false, label %bb93, label %bb94 212 213bb93: ; preds = %bb88 214 unreachable 215 216bb94: ; preds = %bb88 217 %tmp95 = trunc i64 %tmp92 to i32 218 br label %bb96 219 220bb96: ; preds = %bb102, %bb94 221 %tmp97 = phi i64 [ %tmp103, %bb102 ], [ 0, %bb94 ] 222 %tmp98 = phi i32 [ %tmp104, %bb102 ], [ 0, %bb94 ] 223 %tmp99 = trunc i64 %tmp97 to i32 224 %tmp100 = icmp slt i32 %tmp99, %tmp95 225 br i1 %tmp100, label %bb101, label %bb106 226 227bb101: ; preds = %bb96 228 br i1 undef, label %bb105, label %bb102 229 230bb102: ; preds = %bb101 231 %tmp103 = add i64 %tmp97, 1 232 %tmp104 = add nsw i32 %tmp98, 1 233 br i1 false, label %bb106, label %bb96 234 235bb105: ; preds = %bb101 236 br i1 undef, label %bb107, label %bb106 237 238bb106: ; preds = %bb105, %bb102, %bb96 239 br label %bb247 240 241bb107: ; preds = %bb105 242 %tmp108 = add nsw i32 %tmp98, 1 243 %tmp109 = sext i32 %tmp108 to i64 244 %tmp110 = add i64 %tmp109, %tmp91 245 %tmp111 = sub i64 %tmp92, %tmp109 246 br i1 false, label %bb112, label %bb113 247 248bb112: ; preds = %bb107 249 unreachable 250 251bb113: ; preds = %bb107 252 %tmp114 = trunc i64 %tmp111 to i32 253 br label %bb115 254 255bb115: ; preds = %bb121, %bb113 256 %tmp116 = phi i64 [ %tmp122, %bb121 ], [ 0, %bb113 ] 257 %tmp117 = phi i32 [ %tmp123, %bb121 ], [ 0, %bb113 ] 258 %tmp118 = trunc i64 %tmp116 to i32 259 %tmp119 = icmp slt i32 %tmp118, %tmp114 260 br i1 %tmp119, label %bb120, label %bb125 261 262bb120: ; preds = %bb115 263 br i1 undef, label %bb124, label %bb121 264 265bb121: ; preds = %bb120 266 %tmp122 = add i64 %tmp116, 1 267 %tmp123 = add nsw i32 %tmp117, 1 268 br i1 false, label %bb125, label %bb115 269 270bb124: ; preds = %bb120 271 br i1 false, label %bb126, label %bb125 272 273bb125: ; preds = %bb124, %bb121, %bb115 274 unreachable 275 276bb126: ; preds = %bb124 277 %tmp127 = add nsw i32 %tmp117, 1 278 %tmp128 = sext i32 %tmp127 to i64 279 %tmp129 = add i64 %tmp128, %tmp110 280 %tmp130 = sub i64 %tmp111, %tmp128 281 tail call fastcc void @blarg() 282 br i1 false, label %bb132, label %bb131 283 284bb131: ; preds = %bb126 285 unreachable 286 287bb132: ; preds = %bb126 288 %tmp133 = trunc i64 %tmp130 to i32 289 br label %bb134 290 291bb134: ; preds = %bb140, %bb132 292 %tmp135 = phi i64 [ %tmp141, %bb140 ], [ 0, %bb132 ] 293 %tmp136 = phi i32 [ %tmp142, %bb140 ], [ 0, %bb132 ] 294 %tmp137 = trunc i64 %tmp135 to i32 295 %tmp138 = icmp slt i32 %tmp137, %tmp133 296 br i1 %tmp138, label %bb139, label %bb144 297 298bb139: ; preds = %bb134 299 br i1 false, label %bb143, label %bb140 300 301bb140: ; preds = %bb139 302 %tmp141 = add i64 %tmp135, 1 303 %tmp142 = add nsw i32 %tmp136, 1 304 br i1 false, label %bb144, label %bb134 305 306bb143: ; preds = %bb139 307 br i1 false, label %bb145, label %bb144 308 309bb144: ; preds = %bb143, %bb140, %bb134 310 br label %bb247 311 312bb145: ; preds = %bb143 313 %tmp146 = add nsw i32 %tmp136, 1 314 %tmp147 = sext i32 %tmp146 to i64 315 %tmp148 = add i64 %tmp147, %tmp129 316 %tmp149 = sub i64 %tmp130, %tmp147 317 switch i32 0, label %bb152 [ 318 i32 0, label %bb150 319 i32 16, label %bb150 320 i32 32, label %bb150 321 i32 48, label %bb150 322 i32 64, label %bb150 323 i32 256, label %bb150 324 i32 4096, label %bb150 325 ] 326 327bb150: ; preds = %bb145, %bb145, %bb145, %bb145, %bb145, %bb145, %bb145 328 %tmp151 = trunc i64 %tmp149 to i32 329 br label %bb153 330 331bb152: ; preds = %bb145 332 unreachable 333 334bb153: ; preds = %bb160, %bb150 335 %tmp154 = phi i64 [ %tmp161, %bb160 ], [ 0, %bb150 ] 336 %tmp155 = phi i32 [ %tmp162, %bb160 ], [ 0, %bb150 ] 337 %tmp156 = trunc i64 %tmp154 to i32 338 %tmp157 = icmp slt i32 %tmp156, %tmp151 339 br i1 %tmp157, label %bb158, label %bb166 340 341bb158: ; preds = %bb153 342 %tmp159 = add i64 %tmp154, %tmp148 343 br i1 false, label %bb163, label %bb160 344 345bb160: ; preds = %bb158 346 %tmp161 = add i64 %tmp154, 1 347 %tmp162 = add nsw i32 %tmp155, 1 348 br i1 false, label %bb166, label %bb153 349 350bb163: ; preds = %bb158 351 %tmp164 = add i32 %tmp155, -1 352 %tmp165 = icmp ult i32 %tmp164, 255 353 br i1 %tmp165, label %bb167, label %bb166 354 355bb166: ; preds = %bb163, %bb160, %bb153 356 unreachable 357 358bb167: ; preds = %bb163 359 %tmp168 = add nsw i32 %tmp155, 1 360 %tmp169 = sext i32 %tmp168 to i64 361 %tmp170 = add i64 %tmp169, %tmp148 362 %tmp171 = sub i64 %tmp149, %tmp169 363 br i1 false, label %bb173, label %bb172 364 365bb172: ; preds = %bb167 366 unreachable 367 368bb173: ; preds = %bb167 369 %tmp174 = trunc i64 %tmp171 to i32 370 br label %bb175 371 372bb175: ; preds = %bb181, %bb173 373 %tmp176 = phi i64 [ %tmp183, %bb181 ], [ 0, %bb173 ] 374 %tmp177 = phi i32 [ %tmp184, %bb181 ], [ 0, %bb173 ] 375 %tmp178 = trunc i64 %tmp176 to i32 376 %tmp179 = icmp slt i32 %tmp178, %tmp174 377 br i1 %tmp179, label %bb180, label %bb186 378 379bb180: ; preds = %bb175 380 br i1 false, label %bb185, label %bb181 381 382bb181: ; preds = %bb180 383 %tmp182 = icmp eq i8 0, 0 384 %tmp183 = add i64 %tmp176, 1 385 %tmp184 = add nsw i32 %tmp177, 1 386 br i1 %tmp182, label %bb186, label %bb175 387 388bb185: ; preds = %bb180 389 br i1 false, label %bb187, label %bb186 390 391bb186: ; preds = %bb185, %bb181, %bb175 392 unreachable 393 394bb187: ; preds = %bb185 395 %tmp188 = add nsw i32 %tmp177, 1 396 %tmp189 = sext i32 %tmp188 to i64 397 %tmp190 = sub i64 %tmp171, %tmp189 398 br i1 false, label %bb192, label %bb191 399 400bb191: ; preds = %bb187 401 unreachable 402 403bb192: ; preds = %bb187 404 %tmp193 = trunc i64 %tmp190 to i32 405 br label %bb194 406 407bb194: ; preds = %bb200, %bb192 408 %tmp195 = phi i64 [ %tmp201, %bb200 ], [ 0, %bb192 ] 409 %tmp196 = phi i32 [ %tmp202, %bb200 ], [ 0, %bb192 ] 410 %tmp197 = trunc i64 %tmp195 to i32 411 %tmp198 = icmp slt i32 %tmp197, %tmp193 412 br i1 %tmp198, label %bb199, label %bb204 413 414bb199: ; preds = %bb194 415 br i1 false, label %bb203, label %bb200 416 417bb200: ; preds = %bb199 418 %tmp201 = add i64 %tmp195, 1 419 %tmp202 = add nsw i32 %tmp196, 1 420 br i1 false, label %bb204, label %bb194 421 422bb203: ; preds = %bb199 423 br i1 undef, label %bb205, label %bb204 424 425bb204: ; preds = %bb203, %bb200, %bb194 426 unreachable 427 428bb205: ; preds = %bb203 429 %tmp206 = add nsw i32 %tmp196, 1 430 %tmp207 = sext i32 %tmp206 to i64 431 %tmp208 = add i64 %tmp207, 0 432 %tmp209 = sub i64 %tmp190, %tmp207 433 br i1 %tmp13, label %bb210, label %bb211 434 435bb210: ; preds = %bb205 436 unreachable 437 438bb211: ; preds = %bb205 439 %tmp212 = trunc i64 %tmp209 to i32 440 %tmp213 = icmp slt i32 0, %tmp212 441 br i1 false, label %bb215, label %bb214 442 443bb214: ; preds = %bb211 444 unreachable 445 446bb215: ; preds = %bb211 447 %tmp216 = add i64 undef, %tmp208 448 %tmp217 = sub i64 %tmp209, undef 449 br i1 false, label %bb218, label %bb219 450 451bb218: ; preds = %bb215 452 br label %bb219 453 454bb219: ; preds = %bb218, %bb215 455 %tmp220 = trunc i64 %tmp217 to i32 456 br label %bb221 457 458bb221: ; preds = %bb230, %bb219 459 %tmp222 = phi i64 [ %tmp231, %bb230 ], [ 0, %bb219 ] 460 %tmp223 = phi i32 [ %tmp232, %bb230 ], [ 0, %bb219 ] 461 %tmp224 = trunc i64 %tmp222 to i32 462 %tmp225 = icmp slt i32 %tmp224, %tmp220 463 br i1 %tmp225, label %bb226, label %bb234 464 465bb226: ; preds = %bb221 466 %tmp227 = add i64 %tmp222, %tmp216 467 %tmp228 = getelementptr inbounds %struct.jim, %struct.jim* @global3, i64 0, i32 3, i64 %tmp227 468 %tmp229 = load i8, i8* %tmp228, align 1 469 br i1 false, label %bb233, label %bb230 470 471bb230: ; preds = %bb226 472 %tmp231 = add i64 %tmp222, 1 473 %tmp232 = add nsw i32 %tmp223, 1 474 br i1 undef, label %bb234, label %bb221 475 476bb233: ; preds = %bb226 477 br i1 undef, label %bb235, label %bb234 478 479bb234: ; preds = %bb233, %bb230, %bb221 480 br label %bb247 481 482bb235: ; preds = %bb233 483 %tmp236 = add nsw i32 %tmp223, 1 484 %tmp237 = sext i32 %tmp236 to i64 485 %tmp238 = sub i64 %tmp217, %tmp237 486 br i1 %tmp66, label %bb239, label %bb240 487 488bb239: ; preds = %bb235 489 unreachable 490 491bb240: ; preds = %bb235 492 switch i32 0, label %bb244 [ 493 i32 0, label %bb241 494 i32 1, label %bb241 495 i32 4, label %bb241 496 i32 6, label %bb241 497 i32 9, label %bb241 498 ] 499 500bb241: ; preds = %bb240, %bb240, %bb240, %bb240, %bb240 501 %tmp242 = trunc i64 %tmp238 to i32 502 %tmp243 = icmp slt i32 0, %tmp242 503 br i1 false, label %bb246, label %bb245 504 505bb244: ; preds = %bb240 506 unreachable 507 508bb245: ; preds = %bb241 509 unreachable 510 511bb246: ; preds = %bb241 512 unreachable 513 514bb247: ; preds = %bb234, %bb144, %bb106, %bb71, %bb58 515 ret void 516} 517 518declare void @zot(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind 519