1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -mem2reg | %FileCheck %s
import Builtin
//////////////////
// Declarations //
//////////////////
typealias AnyObject = Builtin.AnyObject
struct Int64 {
var _value : Builtin.Int64
}
struct Int {
var _value : Builtin.Int64
}
struct Bool {
var _value : Builtin.Int1
}
enum FakeOptional<T> {
case some(T)
case none
}
class Klass {}
struct SmallCodesizeStruct {
var cls1 : Klass
var cls2 : Klass
}
struct LargeCodesizeStruct {
var s1: SmallCodesizeStruct
var s2: SmallCodesizeStruct
var s3: SmallCodesizeStruct
var s4: SmallCodesizeStruct
var s5: SmallCodesizeStruct
}
class C {}
struct S {
var field: C
}
///////////
// Tests //
///////////
// CHECK-LABEL: sil [ossa] @store_only_allocas :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'store_only_allocas'
// simple.foo0 (c : Swift.Int64) -> ()
sil [ossa] @store_only_allocas : $@convention(thin) (Int64) -> () {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64, var, name "c"
store %0 to [trivial] %1 : $*Int64
// function_ref Swift.print (val : Swift.Int64) -> ()
%3 = function_ref @_Ts5printFT3valSi_T_ : $@convention(thin) (Int64) -> ()
%4 = apply %3(%0) : $@convention(thin) (Int64) -> ()
dealloc_stack %1 : $*Int64
%6 = tuple ()
return %6 : $()
}
// Swift.print (val : Swift.Int64) -> ()
sil [ossa] @_Ts5printFT3valSi_T_ : $@convention(thin) (Int64) -> ()
// CHECK-LABEL: sil [ossa] @multiple_store_vals :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals'
// simple.foo1 (c : Swift.Int64) -> Swift.Int64
sil [ossa] @multiple_store_vals : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64, var, name "c"
store %0 to [trivial] %1 : $*Int64
%3 = alloc_stack $Int64, var, name "x"
%4 = integer_literal $Builtin.Int64, 2
%5 = struct $Int64 (%4 : $Builtin.Int64)
store %5 to [trivial] %3 : $*Int64
%7 = integer_literal $Builtin.Int64, 5
%8 = integer_literal $Builtin.Int1, 0
%9 = struct $Int64 (%7 : $Builtin.Int64)
cond_fail %8 : $Builtin.Int1
store %9 to [trivial] %3 : $*Int64
store %9 to [trivial] %3 : $*Int64
dealloc_stack %3 : $*Int64
dealloc_stack %1 : $*Int64
return %9 : $Int64
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals2 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals2'
// simple.foo2 (c : Swift.Int64) -> Swift.Int64
sil [ossa] @multiple_store_vals2 : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64, var, name "c"
store %0 to [trivial] %1 : $*Int64
%3 = alloc_box $<τ_0_0> { var τ_0_0 } <Int64>, var, name "x"
%3a = project_box %3 : $<τ_0_0> { var τ_0_0 } <Int64>, 0
%4 = integer_literal $Builtin.Int64, 2
%5 = struct $Int64 (%4 : $Builtin.Int64)
store %5 to [trivial] %3a : $*Int64
%8 = struct_extract %0 : $Int64, #Int64._value
%9 = builtin "cmp_sgt_Int64"(%8 : $Builtin.Int64, %4 : $Builtin.Int64) : $Builtin.Int1
cond_br %9, bb1, bb2
bb1:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Int64>
br bb3(%5 : $Int64)
bb2:
%13 = integer_literal $Builtin.Int64, 5
%14 = struct $Int64 (%13 : $Builtin.Int64)
cond_fail %9 : $Builtin.Int1
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Int64>
br bb3(%14 : $Int64)
bb3(%18 : $Int64):
dealloc_stack %1 : $*Int64
return %18 : $Int64
}
// CHECK-LABEL: sil [ossa] @with_loads :
// CHECK: bb3([[RET:%[0-9]+]] : $Int64):
// CHECK-LABEL: } // end sil function 'with_loads'
// simple.foo2 (c : Swift.Int64) -> Swift.Int64
sil [ossa] @with_loads : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64, var, name "c"
store %0 to [trivial] %1 : $*Int64
%3 = alloc_box $<τ_0_0> { var τ_0_0 } <Int64>, var, name "x"
%3a = project_box %3 : $<τ_0_0> { var τ_0_0 } <Int64>, 0
%4 = integer_literal $Builtin.Int64, 2
%5 = struct $Int64 (%4 : $Builtin.Int64)
store %5 to [trivial] %3a : $*Int64
%8 = struct_extract %0 : $Int64, #Int64._value
%9 = builtin "cmp_sgt_Int64"(%8 : $Builtin.Int64, %4 : $Builtin.Int64) : $Builtin.Int1
cond_br %9, bb1, bb2
bb1:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Int64>
br bb3(%5 : $Int64)
bb2:
%13 = integer_literal $Builtin.Int64, 5
%14 = struct $Int64 (%13 : $Builtin.Int64)
cond_fail %9 : $Builtin.Int1
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Int64>
br bb3(%14 : $Int64)
bb3(%18 : $Int64):
%20 = load [trivial] %1 : $*Int64
dealloc_stack %1 : $*Int64
return %18 : $Int64
}
// CHECK-LABEL: sil [ossa] @basic_block_with_loads_and_stores :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'basic_block_with_loads_and_stores'
// test.foo3 (c : Swift.Int64) -> ()
sil [ossa] @basic_block_with_loads_and_stores : $@convention(thin) (Int64) -> () {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64, var, name "c"
store %0 to [trivial] %1 : $*Int64
%3 = alloc_stack $Int64, var, name "x"
%4 = integer_literal $Builtin.Int64, 3
%5 = struct $Int64 (%4 : $Builtin.Int64)
store %5 to [trivial] %3 : $*Int64
%7 = integer_literal $Builtin.Int64, 3
%9 = struct_extract %0 : $Int64, #Int64._value
%10 = builtin "cmp_sgt_Int64"(%9 : $Builtin.Int64, %7 : $Builtin.Int64) : $Builtin.Int1
%12 = integer_literal $Builtin.Int64, 2
%13 = struct $Int64 (%12 : $Builtin.Int64)
store %13 to [trivial] %3 : $*Int64
// function_ref Swift.print (val : Swift.Int64) -> ()
%16 = function_ref @_Ts5printFT3valSi_T_ : $@convention(thin) (Int64) -> ()
%17 = load [trivial] %3 : $*Int64
%18 = apply %16(%17) : $@convention(thin) (Int64) -> ()
dealloc_stack %3 : $*Int64
dealloc_stack %1 : $*Int64
%21 = tuple ()
return %21 : $()
}
// CHECK-LABEL: sil [ossa] @load_uninitialized_empty :
// CHECK-NOT: load
// CHECK-LABEL: } // end sil function 'load_uninitialized_empty'
sil [ossa] @load_uninitialized_empty : $@convention(thin) (@inout ()) -> () {
bb0(%0 : $*()):
%1 = alloc_stack $()
%2 = load [trivial] %1 : $*()
store %2 to [trivial] %0 : $*()
dealloc_stack %1 : $*()
%3 = tuple ()
return %3 : $()
}
// CHECK-LABEL: sil [ossa] @mem2reg_debug_value :
// CHECK-NOT: alloc_stack
// CHECK-NOT: debug_value {{.*}} expr op_deref
// CHECK: debug_value %0
// CHECK-LABEL: } // end sil function 'mem2reg_debug_value'
sil [ossa] @mem2reg_debug_value : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int):
%1 = alloc_stack $Int
store %0 to [trivial] %1 : $*Int
debug_value %1 : $*Int, expr op_deref
%2 = load [trivial] %1 : $*Int
dealloc_stack %1 : $*Int
return %2 : $Int
}
// CHECK-LABEL: sil [ossa] @mem2reg_struct_addr :
// CHECK-NOT: alloc_stack
// CHECK: struct_extract
// CHECK-LABEL: } // end sil function 'mem2reg_struct_addr'
sil [ossa] @mem2reg_struct_addr : $@convention(thin) (Int64) -> Builtin.Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64
store %0 to [trivial] %1 : $*Int64
%2 = struct_element_addr %1 : $*Int64, #Int64._value
%3 = load [trivial] %2 : $*Builtin.Int64
dealloc_stack %1 : $*Int64
return %3 : $Builtin.Int64
}
// CHECK-LABEL: sil [ossa] @mem2reg_tuple_addr :
// CHECK-NOT: alloc_stack
// CHECK: tuple_extract {{.*}}, 0
// CHECK-LABEL: } // end sil function 'mem2reg_tuple_addr'
sil [ossa] @mem2reg_tuple_addr : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $(Int64, Int64)
%2 = tuple (%0 : $Int64, %0 : $Int64)
store %2 to [trivial] %1 : $*(Int64, Int64)
%4 = tuple_element_addr %1 : $*(Int64, Int64), 0
%5 = load [trivial] %4 : $*Int64
dealloc_stack %1 : $*(Int64, Int64)
return %5 : $Int64
}
// CHECK-LABEL: sil [ossa] @struct_extract_if_then_else :
// CHECK-NOT: alloc_stack
sil [ossa] @struct_extract_if_then_else : $@convention(thin) (Int64) -> Int64 {
bb0(%0 : $Int64):
%1 = alloc_stack $Int64
store %0 to [trivial] %1 : $*Int64
%3 = integer_literal $Builtin.Int64, 2
%4 = struct_extract %0 : $Int64, #Int64._value
%5 = builtin "cmp_sgt_Int64"(%4 : $Builtin.Int64, %3 : $Builtin.Int64) : $Builtin.Int1
%6 = struct_element_addr %1 : $*Int64, #Int64._value
cond_br %5, bb1, bb2
// CHECK: bb1:
// CHECK: struct_extract %0
bb1:
%8 = load [trivial] %6 : $*Builtin.Int64
%9 = integer_literal $Builtin.Int64, 1
%10 = integer_literal $Builtin.Int1, 0
%11 = builtin "sadd_with_overflow_Int64"(%8 : $Builtin.Int64, %9 : $Builtin.Int64, %10 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
%12 = tuple_extract %11 : $(Builtin.Int64, Builtin.Int1), 0
br bb3(%12 : $Builtin.Int64)
// CHECK: bb2:
// CHECK: struct_extract %0
bb2:
%14 = load [trivial] %6 : $*Builtin.Int64
%15 = integer_literal $Builtin.Int64, 2
%16 = integer_literal $Builtin.Int1, 0
%17 = builtin "sadd_with_overflow_Int64"(%14 : $Builtin.Int64, %15 : $Builtin.Int64, %16 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
%18 = tuple_extract %17 : $(Builtin.Int64, Builtin.Int1), 0
br bb3(%18 : $Builtin.Int64)
// CHECK-NOT: dealloc_stack
bb3(%20 : $Builtin.Int64):
dealloc_stack %1 : $*Int64
%22 = struct $Int64 (%20 : $Builtin.Int64)
return %22 : $Int64
}
// CHECK-LABEL: } // end sil function 'struct_extract_if_then_else'
sil [ossa] @first : $@convention(thin) () -> Int
sil [ossa] @second : $@convention(thin) () -> Int
// CHECK: sil [ossa] @promote_function_refs :
sil [ossa] @promote_function_refs : $@convention(thin) (Bool) -> Int {
// CHECK: bb0
bb0(%0 : $Bool):
// CHECK-NOT: [[STACK:%.*]] = alloc_stack
%1 = alloc_stack $@callee_owned () -> Int
debug_value %0 : $Bool
%3 = struct_extract %0 : $Bool, #Bool._value
cond_br %3, bb1, bb2
// CHECK: bb1
bb1:
// CHECK: [[FIRSTREF:%.*]] = function_ref @first
%5 = function_ref @first : $@convention(thin) () -> Int
// CHECK: [[FIRSTTHICK:%.*]] = thin_to_thick_function [[FIRSTREF]]
%6 = thin_to_thick_function %5 : $@convention(thin) () -> Int to $@callee_owned () -> Int
// CHECK-NOT: store
store %6 to [init] %1 : $*@callee_owned () -> Int
// CHECK: br bb3([[FIRSTTHICK]] : $@callee_owned () -> Int
br bb3
// CHECK: bb2
bb2:
// CHECK: [[SECONDREF:%.*]] = function_ref @second
%9 = function_ref @second : $@convention(thin) () -> Int
// CHECK: [[SECONDTHICK:%.*]] = thin_to_thick_function [[SECONDREF]]
%10 = thin_to_thick_function %9 : $@convention(thin) () -> Int to $@callee_owned () -> Int
// CHECK-NOT: store
store %10 to [init] %1 : $*@callee_owned () -> Int
// CHECK: br bb3([[SECONDTHICK]] : $@callee_owned () -> Int)
br bb3
// CHECK: bb3([[ARG:%.*]] : @owned $@callee_owned () -> Int):
bb3:
// CHECK-NOT: load
%13 = load [copy] %1 : $*@callee_owned () -> Int
// : [[COPY:%.*]] = copy_value [[ARG]]
// The above copy is eliminated by owned value canonicalization.
// CHECK: [[RESULT:%.*]] = apply [[ARG]]
%15 = apply %13() : $@callee_owned () -> Int
br bb4
// NOTE: This block and the branch above exist to ensure that we
// test what happens when %1 hasn't already been loaded in this
// block.
// CHECK: bb4
bb4:
// CHECK-NOT: destroy_addr
// : destroy_value [[ARG]]
// The above destroy is eliminated by owned value canonicalization.
destroy_addr %1 : $*@callee_owned () -> Int
// CHECK-NOT: dealloc_stack
dealloc_stack %1 : $*@callee_owned () -> Int
return %15 : $Int
}
// CHECK-LABEL: } // end sil function 'promote_function_refs'
// Test cases where the only use is a debug_value_addr
// CHECK-LABEL: sil [ossa] @no_real_uses :
sil [ossa] @no_real_uses : $@convention(thin) () -> () {
// CHECK: bb0
bb0:
// CHECK-NOT: alloc_stack
%0 = alloc_stack [dynamic_lifetime] $Builtin.Int32
// CHECK-NOT: debug_value {{.*}} expr op_deref
debug_value %0 : $*Builtin.Int32, let, name "x", argno 1, expr op_deref
// CHECK-NOT: dealloc_stack
dealloc_stack %0 : $*Builtin.Int32
%1 = tuple ()
return %1 : $()
}
// CHECK-LABEL: } // end sil function 'no_real_uses'
// CHECK-LABEL: sil [ossa] @keep_release :
// CHECK: destroy_value %0
// CHECK-LABEL: } // end sil function 'keep_release'
sil [ossa] @keep_release : $@convention(thin) (@owned AnyObject) -> () {
bb0(%0 : @owned $AnyObject):
%1 = alloc_stack $AnyObject
store %0 to [init] %1 : $*AnyObject
destroy_addr %1 : $*AnyObject
dealloc_stack %1 : $*AnyObject
%7 = tuple ()
return %7 : $()
}
// Test cases where there are dead address instructions.
// CHECK-LABEL: sil [ossa] @dead_use :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'dead_use'
sil [ossa] @dead_use : $@convention(thin) () -> () {
%0 = alloc_stack $Int64
%1 = struct_element_addr %0 : $*Int64, #Int64._value
dealloc_stack %0 : $*Int64
%2 = alloc_stack $(Int64, Int64)
%3 = tuple_element_addr %2 : $*(Int64, Int64), 0
dealloc_stack %2 : $*(Int64, Int64)
%4 = tuple ()
return %4 : $()
}
// CHECK-LABEL: sil [ossa] @dont_crash_on_dead_arg_use :
// CHECK: bb0{{.*}}:
// CHECK: tuple ()
// CHECK-LABEL: } // end sil function 'dont_crash_on_dead_arg_use'
sil [ossa] @dont_crash_on_dead_arg_use : $@convention(thin) (@inout Int64) -> () {
bb0(%0 : $*Int64):
%2 = alloc_stack $Int64
%1 = struct_element_addr %0 : $*Int64, #Int64._value
%3 = struct_element_addr %2 : $*Int64, #Int64._value
dealloc_stack %2 : $*Int64
%4 = tuple ()
return %4 : $()
}
// Make sure that we do expand destroy_addr appropriately for code-size
// trade-offs.
// CHECK-LABEL: sil [ossa] @large_struct_test :
// CHECK: bb0([[ARG0:%.*]] : @owned $LargeCodesizeStruct):
// CHECK: destroy_value [[ARG0]]
// CHECK: } // end sil function 'large_struct_test'
sil [ossa] @large_struct_test : $@convention(thin) (@owned LargeCodesizeStruct) -> () {
bb0(%0 : @owned $LargeCodesizeStruct):
%1 = alloc_stack $LargeCodesizeStruct
store %0 to [init] %1 : $*LargeCodesizeStruct
destroy_addr %1 : $*LargeCodesizeStruct
dealloc_stack %1 : $*LargeCodesizeStruct
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @small_struct_test :
// CHECK: bb0([[ARG0:%.*]] : @owned $SmallCodesizeStruct):
// CHECK: ([[ELEM1:%[0-9]+]], [[ELEM2:%[0-9]+]]) = destructure_struct [[ARG0]]
// CHECK: destroy_value [[ELEM1]]
// CHECK: destroy_value [[ELEM2]]
// CHECK: } // end sil function 'small_struct_test'
sil [ossa] @small_struct_test : $@convention(thin) (@owned SmallCodesizeStruct) -> () {
bb0(%0 : @owned $SmallCodesizeStruct):
%1 = alloc_stack $SmallCodesizeStruct
store %0 to [init] %1 : $*SmallCodesizeStruct
destroy_addr %1 : $*SmallCodesizeStruct
dealloc_stack %1 : $*SmallCodesizeStruct
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @small_struct_multi_test :
// CHECK-NOT: alloc_stack
// CHECK: [[COPY:%.*]] = copy_value %0
// CHECK-NEXT: destructure_struct %2
// CHECK-NEXT: destroy_value
// CHECK-NEXT: destroy_value
// CHECK-NEXT: begin_borrow %0
// CHECK-NEXT: debug_value
// CHECK-NEXT: end_borrow
// CHECK-NEXT: destroy_value %0
// CHECK: bb2:
// CHECK-NEXT: destructure_struct %0
// CHECK-NEXT: destroy_value
// CHECK-NEXT: destroy_value
// CHECK-LABEL: } // end sil function 'small_struct_multi_test'
sil [ossa] @small_struct_multi_test : $@convention(thin) (@owned SmallCodesizeStruct) -> () {
bb0(%0 : @owned $SmallCodesizeStruct):
%1 = alloc_stack $SmallCodesizeStruct
store %0 to [init] %1 : $*SmallCodesizeStruct
cond_br undef, bb1, bb2
bb1:
%3 = load [copy] %1 : $*SmallCodesizeStruct
destroy_addr %1 : $*SmallCodesizeStruct
dealloc_stack %1 : $*SmallCodesizeStruct
%4 = begin_borrow %3 : $SmallCodesizeStruct
debug_value %4 : $SmallCodesizeStruct
end_borrow %4 : $SmallCodesizeStruct
destroy_value %3 : $SmallCodesizeStruct
br bb3
bb2:
destroy_addr %1 : $*SmallCodesizeStruct
dealloc_stack %1 : $*SmallCodesizeStruct
br bb3
bb3:
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @dead_address_projections :
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'dead_address_projections'
sil [ossa] @dead_address_projections : $@convention(thin) (((), ())) -> ((), ()) {
bb0(%0 : $((), ())):
%1 = alloc_stack $((), ())
%200 = tuple_element_addr %1 : $*((), ()), 0
%300 = tuple_element_addr %1 : $*((), ()), 1
cond_br undef, bb1, bb2
bb1:
store %0 to [trivial] %1 : $*((), ())
%16 = load [trivial] %1 : $*((), ())
dealloc_stack %1 : $*((), ())
br bb3(%16 : $((), ()))
bb2:
dealloc_stack %1 : $*((), ())
br bb3(%0 : $((), ()))
bb3(%20 : $((), ())):
return %20 : $((), ())
}
// CHECK-LABEL: sil [ossa] @load_tuple_of_void :
// CHECK-NOT: alloc_stack
// CHECK: [[T:%[0-9]+]] = tuple (%{{[0-9]+}} : $(), %{{[0-9]+}} : $())
// CHECK: return [[T]] : $((), ())
// CHECK: } // end sil function 'load_tuple_of_void'
sil [ossa] @load_tuple_of_void : $@convention(thin) () -> ((), ()) {
bb0:
%1 = alloc_stack $((), ())
%16 = load [trivial] %1 : $*((), ())
dealloc_stack %1 : $*((), ())
return %16 : $((), ())
}
// CHECK-LABEL: sil [ossa] @test_optional_in_multiple_blocks :
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'test_optional_in_multiple_blocks'
sil [ossa] @test_optional_in_multiple_blocks : $@convention(method) (@guaranteed FakeOptional<Klass>) -> () {
bb0(%0 : @guaranteed $FakeOptional<Klass>):
%1 = copy_value %0 : $FakeOptional<Klass>
%32 = alloc_stack $FakeOptional<Klass>
store %1 to [init] %32 : $*FakeOptional<Klass>
switch_enum %0 : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb6, case #FakeOptional.none!enumelt: bb5
bb5:
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb6(%50 : @guaranteed $Klass):
%53 = load [copy] %32 : $*FakeOptional<Klass>
destroy_value %53 : $FakeOptional<Klass>
destroy_addr %32 : $*FakeOptional<Klass>
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb7:
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @test_optional_in_multiple_blocks_lexical :
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'test_optional_in_multiple_blocks_lexical'
sil [ossa] @test_optional_in_multiple_blocks_lexical : $@convention(method) (@guaranteed FakeOptional<Klass>) -> () {
bb0(%0 : @guaranteed $FakeOptional<Klass>):
%1 = copy_value %0 : $FakeOptional<Klass>
%32 = alloc_stack [lexical] $FakeOptional<Klass>
store %1 to [init] %32 : $*FakeOptional<Klass>
switch_enum %0 : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb6, case #FakeOptional.none!enumelt: bb5
bb5:
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb6(%50 : @guaranteed $Klass):
%53 = load [copy] %32 : $*FakeOptional<Klass>
destroy_value %53 : $FakeOptional<Klass>
destroy_addr %32 : $*FakeOptional<Klass>
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb7:
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @test_optional_in_multiple_blocks_lexical_storedvalue :
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'test_optional_in_multiple_blocks_lexical_storedvalue'
sil [ossa] @test_optional_in_multiple_blocks_lexical_storedvalue : $@convention(method) (@owned FakeOptional<Klass>) -> () {
bb0(%0 : @owned $FakeOptional<Klass>):
%1 = copy_value %0 : $FakeOptional<Klass>
%32 = alloc_stack $FakeOptional<Klass>
store %0 to [init] %32 : $*FakeOptional<Klass>
switch_enum %1 : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb6, case #FakeOptional.none!enumelt: bb5
bb5:
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb6(%50 : @owned $Klass):
%53 = load [copy] %32 : $*FakeOptional<Klass>
destroy_value %53 : $FakeOptional<Klass>
destroy_value %50 : $Klass
destroy_addr %32 : $*FakeOptional<Klass>
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb7:
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @optimize_optional_in_single_block :
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'optimize_optional_in_single_block'
sil [ossa] @optimize_optional_in_single_block : $@convention(method) (@guaranteed FakeOptional<Klass>) -> () {
bb0(%0 : @guaranteed $FakeOptional<Klass>):
switch_enum %0 : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb6, case #FakeOptional.none!enumelt: bb5
bb5:
br bb7
bb6(%50 : @guaranteed $Klass):
%32 = alloc_stack $FakeOptional<Klass>
%1 = copy_value %0 : $FakeOptional<Klass>
store %1 to [init] %32 : $*FakeOptional<Klass>
%53 = load [take] %32 : $*FakeOptional<Klass>
destroy_value %53 : $FakeOptional<Klass>
dealloc_stack %32 : $*FakeOptional<Klass>
br bb7
bb7:
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @switch_enum_out_of_new_phi_block : {{.*}} {
// CHECK-NOT: alloc_stack
// CHECK: } // end sil function 'switch_enum_out_of_new_phi_block'
sil [ossa] @switch_enum_out_of_new_phi_block : $() -> () {
entry:
%addr = alloc_stack $FakeOptional<Klass>
cond_br undef, store_none, agg_either
store_none:
%none1 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
store %none1 to [init] %addr : $*FakeOptional<Klass>
br switcheroo
agg_either:
cond_br undef, agg_some, agg_none
agg_some:
%Klass = apply undef() : $@convention(thin) () -> (@owned Klass)
%some = enum $FakeOptional<Klass>, #FakeOptional.some!enumelt, %Klass : $Klass
br store_maybe(%some : $FakeOptional<Klass>)
agg_none:
%none2 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
br store_maybe(%none2 : $FakeOptional<Klass>)
store_maybe(%maybe : @owned $FakeOptional<Klass>):
store %maybe to [init] %addr : $*FakeOptional<Klass>
br switcheroo
switcheroo:
%borrow = load_borrow %addr : $*FakeOptional<Klass>
switch_enum %borrow : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb14, case #FakeOptional.none!enumelt: bb15
bb14(%some_borrowed : @guaranteed $Klass):
end_borrow %borrow : $FakeOptional<Klass>
destroy_addr %addr : $*FakeOptional<Klass>
br bb16
bb15:
end_borrow %borrow : $FakeOptional<Klass>
br bb16
bb16:
dealloc_stack %addr : $*FakeOptional<Klass>
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @debug_value_of_store_borrow_addr_multi_block : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
// CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [[INSTANCE]]
// CHECK: debug_value [[LIFETIME]]
// CHECK-LABEL: } // end sil function 'debug_value_of_store_borrow_addr_multi_block'
sil [ossa] @debug_value_of_store_borrow_addr_multi_block : $@convention(thin) (@owned S) -> () {
entry(%instance : @owned $S):
br header
header:
%lifetime = begin_borrow %instance : $S
%stack = alloc_stack $S
%stack_borrow = store_borrow %lifetime to %stack : $*S
debug_value %stack_borrow : $*S
br body
body:
%field_addr = struct_element_addr %stack_borrow : $*S, #S.field
%field = load [copy] %field_addr : $*C
end_borrow %stack_borrow : $*S
dealloc_stack %stack : $*S
end_borrow %lifetime : $S
destroy_value %field : $C
cond_br undef, backedge, exit
backedge:
br header
exit:
destroy_value %instance : $S
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @debug_value_of_store_borrow_addr_single_block : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
// CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [[INSTANCE]]
// CHECK: debug_value [[LIFETIME]]
// CHECK-LABEL: } // end sil function 'debug_value_of_store_borrow_addr_single_block'
sil [ossa] @debug_value_of_store_borrow_addr_single_block : $@convention(thin) (@owned S) -> () {
entry(%instance : @owned $S):
br header
header:
%lifetime = begin_borrow %instance : $S
%stack = alloc_stack $S
%stack_borrow = store_borrow %lifetime to %stack : $*S
debug_value %stack_borrow : $*S
%field_addr = struct_element_addr %stack_borrow : $*S, #S.field
%field = load [copy] %field_addr : $*C
end_borrow %stack_borrow : $*S
dealloc_stack %stack : $*S
end_borrow %lifetime : $S
destroy_value %field : $C
cond_br undef, backedge, exit
backedge:
br header
exit:
destroy_value %instance : $S
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @dont_canonicalize_undef : {{.*}} {
// CHECK: [[RETVAL:%[^,]+]] = tuple
// CHECK: return [[RETVAL]]
// CHECK-LABEL: } // end sil function 'dont_canonicalize_undef'
sil [ossa] @dont_canonicalize_undef : $@convention(thin) () -> () {
%addr = alloc_stack $()
store undef to [trivial] %addr : $*()
dealloc_stack %addr : $*()
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @dont_canonicalize_erased_copy : {{.*}} {
// CHECK: bb0(%0 :
// CHECK: destroy_value %0
// CHECK-LABEL: } // end sil function 'dont_canonicalize_erased_copy'
sil [ossa] @dont_canonicalize_erased_copy : $@convention(thin) (@owned C) -> () {
entry(%instance : @owned $C):
%stack = alloc_stack $C
%copy = copy_value %instance : $C
store %copy to [init] %stack : $*C
%loaded_copy = load [take] %stack : $*C
destroy_value %loaded_copy : $C
store %instance to [init] %stack : $*C
%loaded_instance = load [take] %stack : $*C
destroy_value %loaded_instance : $C
dealloc_stack %stack : $*C
%retval = tuple ()
return %retval : $()
}
|