|
1 |
| -// RUN: %target-sil-opt -tf-xla-cfg-canonicalize -tf-ensure-single-loop-exit -assume-parsing-unqualified-ownership-sil %s -o /dev/null | %FileCheck %s |
| 1 | +// RUN: %target-sil-opt -tf-dump-intermediates -tf-xla-cfg-canonicalize -tf-ensure-single-loop-exit -assume-parsing-unqualified-ownership-sil %s -o /dev/null | %FileCheck %s |
2 | 2 |
|
3 | 3 | import Builtin
|
4 | 4 | import Swift
|
@@ -361,3 +361,88 @@ bb8:
|
361 | 361 | bb9(%18 : $Builtin.Int32):
|
362 | 362 | return %18 : $Builtin.Int32
|
363 | 363 | }
|
| 364 | + |
| 365 | +// The following example is similar to loopThatRequiresNodeCloning, where the |
| 366 | +// nodes that lead to the common post dominator of all exit nodes is also |
| 367 | +// reachable from nodes outside of the loop. The only difference in this example |
| 368 | +// is that some of these nodes also belong to a loop. Therefore, it is required |
| 369 | +// for us to update the LoopInfo in addition to cloning. The loop in question |
| 370 | +// consists of the single node bb3. |
| 371 | + |
| 372 | +// CHECK-LABEL:--- XLA CFG Loops Before Canonicalize: $loopThatRequiresNodeAndLoopCloning |
| 373 | +//----The following loop will be cloned in the second loop. |
| 374 | +// CHECK:Loop at depth 1 containing: {{bb[0-9]+}}<header><latch><exiting> |
| 375 | +// CHECK:Loop at depth 1 containing: {{bb[0-9]+}}<header><exiting>,{{bb[0-9]+}}<exiting>,{{bb[0-9]+}}<latch> |
| 376 | + |
| 377 | +// CHECK-LABEL:--- XLA CFG Loops After Canonicalize: $loopThatRequiresNodeAndLoopCloning |
| 378 | +// CHECK:Loop at depth 1 containing: [[L1HDR:bb[0-9]+]]<header><exiting>,[[L1LATCH:bb[0-9]+]]<latch> |
| 379 | +// CHECK:Loop at depth 1 containing: [[L2HDR:bb[0-9]+]]<header><exiting>,{{.*}},[[L2LATCH:bb[0-9]+]]<latch> |
| 380 | +//----Following is the clone of the first loop. |
| 381 | +// CHECK: Loop at depth 2 containing: [[L3HDR:bb[0-9]+]]<header><exiting>,[[L3LATCH:bb[0-9]+]]<latch> |
| 382 | + |
| 383 | +// CHECK-LABEL:--- XLA CFG Canonicalize: $loopThatRequiresNodeAndLoopCloning |
| 384 | +// CHECK:[sequence |
| 385 | +// CHECK: {condition Header: {{bb[0-9]+}} |
| 386 | +// CHECK: [sequence |
| 387 | +// CHECK: <while Preheader: {{bb[0-9]+}}, Header: [[L1HDR]], exit: {{bb[0-9]+}} |
| 388 | +// CHECK: block [[L1LATCH]]> |
| 389 | +// CHECK: block {{bb[0-9]+}}] |
| 390 | +// CHECK: [sequence |
| 391 | +// CHECK: <while Preheader: {{bb[0-9]+}}, Header: [[L2HDR]], exit: {{bb[0-9]+}} |
| 392 | +// CHECK: [sequence |
| 393 | +// CHECK: {condition Header: {{bb[0-9]+}} |
| 394 | +// CHECK: block {{bb[0-9]+}} |
| 395 | +// CHECK: {condition Header: {{bb[0-9]+}} |
| 396 | +// CHECK: [sequence |
| 397 | +// CHECK: <while Preheader: {{bb[0-9]+}}, Header: [[L3HDR]], exit: {{bb[0-9]+}} |
| 398 | +// CHECK: block [[L3LATCH]]> |
| 399 | +// CHECK: block {{bb[0-9]+}}] |
| 400 | +// CHECK: block {{bb[0-9]+}}}} |
| 401 | +// CHECK: block [[L2LATCH]]]> |
| 402 | +// CHECK: block {{bb[0-9]+}}]} |
| 403 | +// CHECK: block {{bb[0-9]+}}] |
| 404 | + |
| 405 | +sil @$loopThatRequiresNodeAndLoopCloning : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> Builtin.Int32 { |
| 406 | +bb0(%0 : $Builtin.Int32, %1 : $Builtin.Int32): |
| 407 | + %2 = integer_literal $Builtin.Int32, 1 |
| 408 | + %3 = integer_literal $Builtin.Int32, 100 |
| 409 | + %4 = builtin "sadd_with_overflow_Int32"(%0 : $Builtin.Int32, %2 : $Builtin.Int32) : $Builtin.Int32 |
| 410 | + %5 = builtin "cmp_slt_Int32"(%4 : $Builtin.Int32, %3 : $Builtin.Int32) : $Builtin.Int1 |
| 411 | + cond_br %5, bb1, bb2 |
| 412 | + |
| 413 | +bb1: |
| 414 | + // First arg is sum, the second arg is loop counter. |
| 415 | + br bb3(%4 : $Builtin.Int32, %0 : $Builtin.Int32) |
| 416 | + |
| 417 | +bb2: |
| 418 | + br bb4(%4 : $Builtin.Int32, %0 : $Builtin.Int32) |
| 419 | + |
| 420 | +bb3(%6 : $Builtin.Int32, %7 : $Builtin.Int32): |
| 421 | + %8 = builtin "ssub_with_overflow_Int32"(%6 : $Builtin.Int32, %7 : $Builtin.Int32) : $Builtin.Int32 |
| 422 | + %100 = builtin "cmp_slt_Int32"(%8 : $Builtin.Int32, %7 : $Builtin.Int32) : $Builtin.Int1 |
| 423 | + cond_br %100, bb3(%7: $Builtin.Int32, %8: $Builtin.Int32), bb9(%8 : $Builtin.Int32) |
| 424 | + |
| 425 | +bb4(%9 : $Builtin.Int32, %10 : $Builtin.Int32): |
| 426 | + %11 = builtin "sadd_with_overflow_Int32"(%10 : $Builtin.Int32, %2 : $Builtin.Int32) : $Builtin.Int32 |
| 427 | + %12 = builtin "sadd_with_overflow_Int32"(%9 : $Builtin.Int32, %10 : $Builtin.Int32) : $Builtin.Int32 |
| 428 | + %13 = builtin "cmp_slt_Int32"(%11 : $Builtin.Int32, %1 : $Builtin.Int32) : $Builtin.Int1 |
| 429 | + cond_br %13, bb5, bb6 |
| 430 | + |
| 431 | +bb5: |
| 432 | + br bb9(%12 : $Builtin.Int32) |
| 433 | + |
| 434 | +bb6: |
| 435 | + %14 = builtin "sadd_with_overflow_Int32"(%11 : $Builtin.Int32, %2 : $Builtin.Int32) : $Builtin.Int32 |
| 436 | + %15 = builtin "sadd_with_overflow_Int32"(%12 : $Builtin.Int32, %14 : $Builtin.Int32) : $Builtin.Int32 |
| 437 | + %16 = builtin "cmp_slt_Int32"(%14 : $Builtin.Int32, %1 : $Builtin.Int32) : $Builtin.Int1 |
| 438 | + cond_br %16, bb8, bb7 |
| 439 | + |
| 440 | +bb7: |
| 441 | + br bb4(%15 : $Builtin.Int32, %14 : $Builtin.Int32) |
| 442 | + |
| 443 | +bb8: |
| 444 | + br bb3(%15 : $Builtin.Int32, %14 : $Builtin.Int32) |
| 445 | + |
| 446 | +bb9(%18 : $Builtin.Int32): |
| 447 | + return %18 : $Builtin.Int32 |
| 448 | +} |
0 commit comments