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 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -mem2reg | %FileCheck %s
import Builtin
import Swift
//////////////////
// Declarations //
//////////////////
typealias AnyObject = Builtin.AnyObject
class Klass {}
class X {}
struct S {
var v1: AnyObject
var v2: AnyObject
}
struct SmallCodesizeStruct {
var cls1 : Klass
var cls2 : Klass
}
struct WrapperStruct {
var cls : Klass
}
struct LargeCodesizeStruct {
var s1: SmallCodesizeStruct
var s2: SmallCodesizeStruct
var s3: SmallCodesizeStruct
var s4: SmallCodesizeStruct
var s5: SmallCodesizeStruct
}
public enum NonTrivialEnum {
case some1(Klass)
case some2(NonTrivialStruct)
}
struct NonTrivialStruct {
var val:Klass
}
public enum FakeOptional<T> {
case some(T)
case none
}
struct UInt8 {
var _value : Builtin.Int8
}
enum KlassOptional {
case some(Klass)
case none
}
sil [ossa] @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
sil [ossa] @get_nontrivialenum : $@convention(thin) () -> @owned NonTrivialEnum
sil [ossa] @get_optionalnontrivialstruct : $@convention(thin) () -> @owned FakeOptional<NonTrivialStruct>
sil [ossa] @take_nontrivialstruct : $@convention(thin) (@owned NonTrivialStruct) -> ()
///////////
// Tests //
///////////
sil [noinline] [ossa] @blackhole : $@convention(thin) <T> (@in_guaranteed T) -> () {
bb0(%0 : $*T):
debug_value %0 : $*T, let, name "t", argno 1, expr op_deref
%2 = tuple ()
return %2 : $()
}
sil shared [noinline] @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : $Klass):
%1 = tuple ()
return %1 : $()
}
// CHECK-LABEL: sil [ossa] @store_only_allocas :
// CHECK-NOT: alloc_stack
// CHECK: return
sil [ossa] @store_only_allocas : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
%2 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%3 = load [take] %1 : $*Klass
%4 = apply %2(%3) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %3 : $Klass
dealloc_stack %1 : $*Klass
%6 = tuple ()
return %6 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals :
// CHECK-NOT: alloc_stack
// CHECK: destroy_value %0 : $Klass
// CHECK: [[FUNC:%.*]] = function_ref @blackhole_spl :
// CHECK: apply [[FUNC]](%1) : $@convention(thin) (@guaranteed Klass) -> ()
// CHECK: destroy_value %1 : $Klass
// CHECK-LABEL: } // end sil function 'multiple_store_vals'
sil [ossa] @multiple_store_vals : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
store %1 to [assign] %2 : $*Klass
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %2 : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %2 : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals2 :
// CHECK-NOT: alloc_stack
// CHECK: destroy_value %0 : $Klass
// CHECK: [[FUNC:%.*]] = function_ref @blackhole_spl :
// CHECK: apply [[FUNC]](%1) : $@convention(thin) (@guaranteed Klass) -> ()
// CHECK: destroy_value %1 : $Klass
// CHECK-LABEL: } // end sil function 'multiple_store_vals2'
sil [ossa] @multiple_store_vals2 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
destroy_addr %2 : $*Klass
store %1 to [init] %2 : $*Klass
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %2 : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %2 : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals3 :
// CHECK-NOT: alloc_stack
// The COPY0 copy/destroy is eliminated by owned value canonicalization.
// : [[COPY0:%.*]] = copy_value %0 : $Klass
// CHECK: [[COPY1:%.*]] = copy_value %1 : $Klass
// : destroy_value [[COPY0]] : $Klass
// CHECK: [[FUNC:%.*]] = function_ref @blackhole_spl :
// CHECK: apply [[FUNC]]([[COPY1]]) : $@convention(thin) (@guaranteed Klass) -> ()
// CHECK: destroy_value [[COPY1]] : $Klass
// CHECK-LABEL: } // end sil function 'multiple_store_vals3'
sil [ossa] @multiple_store_vals3 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
%2 = alloc_stack $Klass
%copy0 = copy_value %0 : $Klass
store %copy0 to [init] %2 : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
%copy1 = copy_value %1 : $Klass
store %copy1 to [assign] %2 : $*Klass
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %2 : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %2 : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals4 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals4'
sil [ossa] @multiple_store_vals4 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = alloc_box $<τ_0_0> { var τ_0_0 } <Klass>
%3a = project_box %3 : $<τ_0_0> { var τ_0_0 } <Klass>, 0
store %1 to [assign] %2 : $*Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb2:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb3:
destroy_addr %2 : $*Klass
dealloc_stack %2 : $*Klass
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals5 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals5'
sil [ossa] @multiple_store_vals5 : $@convention(thin) (@owned Klass, @owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass, %2 : @owned $Klass):
%stk = alloc_stack $Klass
store %0 to [init] %stk : $*Klass
%3 = alloc_box $<τ_0_0> { var τ_0_0 } <Klass>
%3a = project_box %3 : $<τ_0_0> { var τ_0_0 } <Klass>, 0
store %1 to [assign] %stk : $*Klass
store %2 to [assign] %stk : $*Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb2:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb3:
destroy_addr %stk : $*Klass
dealloc_stack %stk : $*Klass
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals6 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals6'
sil [ossa] @multiple_store_vals6 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
br bb1
bb1:
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
store %1 to [assign] %2 : $*Klass
br bb2
bb2:
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %2 : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %2 : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals7 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals7'
sil [ossa] @multiple_store_vals7 : $@convention(thin) (@owned Klass, @owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass, %2 : @owned $Klass):
%stk = alloc_stack $Klass
store %0 to [init] %stk : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
br bb1
bb1:
store %1 to [assign] %stk : $*Klass
store %2 to [assign] %stk : $*Klass
br bb2
bb2:
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %stk : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %stk : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_store_vals8 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_store_vals8'
sil [ossa] @multiple_store_vals8 : $@convention(thin) (@owned Klass, @owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass, %2 : @owned $Klass):
%stk = alloc_stack $Klass
store %0 to [init] %stk : $*Klass
%3 = integer_literal $Builtin.Int1, 0
cond_fail %3 : $Builtin.Int1
br bb1
bb1:
store %1 to [assign] %stk : $*Klass
destroy_addr %stk : $*Klass
store %2 to [init] %stk : $*Klass
br bb2
bb2:
%4 = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%5 = load [take] %stk : $*Klass
%6 = apply %4(%5) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %5 : $Klass
dealloc_stack %stk : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @with_loads :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'with_loads'
sil [ossa] @with_loads : $@convention(thin) (@owned Klass, @owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = alloc_box $<τ_0_0> { var τ_0_0 } <Klass>
%3a = project_box %3 : $<τ_0_0> { var τ_0_0 } <Klass>, 0
store %1 to [assign] %2 : $*Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb2:
destroy_value %3 : $<τ_0_0> { var τ_0_0 } <Klass>
br bb3
bb3:
%ret = load [take] %2 : $*Klass
dealloc_stack %2 : $*Klass
return %ret : $Klass
}
// 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'
sil [ossa] @basic_block_with_loads_and_stores : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
%3 = alloc_stack $Klass
store %1 to [init] %3 : $*Klass
%local = alloc_ref $Klass
store %local to [assign] %3 : $*Klass
%func = function_ref @blackhole_spl : $@convention(thin) (@guaranteed Klass) -> ()
%arg = load [take] %3 : $*Klass
%applyres = apply %func(%arg) : $@convention(thin) (@guaranteed Klass) -> ()
destroy_value %arg : $Klass
destroy_addr %2 : $*Klass
dealloc_stack %3 : $*Klass
dealloc_stack %2 : $*Klass
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @basic_block_with_loads_copy_and_take :
// CHECK-NOT: alloc_stack
// The COPY/destroy pair is eliminated by owned value canonicalization.
// : [[COPY:%.*]] = copy_value %0 : $Klass
// : destroy_value [[COPY]] : $Klass
// CHECK: destroy_value %0 : $Klass
// CHECK-LABEL: } // end sil function 'basic_block_with_loads_copy_and_take'
sil [ossa] @basic_block_with_loads_copy_and_take : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
%copy = load [copy] %1 : $*Klass
%take = load [take] %1 : $*Klass
destroy_value %copy : $Klass
destroy_value %take : $Klass
dealloc_stack %1 : $*Klass
%res = tuple ()
return %res : $()
}
// load [copy] is not used as RunningVal
// StackAllocationPromoter::fixBranchesAndUses will delete the loads and replace with %0
// CHECK-LABEL: sil [ossa] @multi_basic_block_with_loads_copy_and_take_1 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multi_basic_block_with_loads_copy_and_take_1'
sil [ossa] @multi_basic_block_with_loads_copy_and_take_1 : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
br bb1
bb1:
%copy = load [copy] %1 : $*Klass
%take = load [take] %1 : $*Klass
destroy_value %copy : $Klass
destroy_value %take : $Klass
dealloc_stack %1 : $*Klass
%res = tuple ()
return %res : $()
}
// load [copy] is not used as RunningVal
// StackAllocationPromoter::fixBranchesAndUses will delete the loads and replace with %0
// CHECK-LABEL: sil [ossa] @multi_basic_block_with_loads_copy_and_take_2 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multi_basic_block_with_loads_copy_and_take_2'
sil [ossa] @multi_basic_block_with_loads_copy_and_take_2 : $@convention(thin) (@owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
br bb1
bb1:
%copy = load [copy] %1 : $*Klass
%take = load [take] %1 : $*Klass
destroy_value %take : $Klass
dealloc_stack %1 : $*Klass
return %copy : $Klass
}
// load [take] is used as RunningVal in bb1
// CHECK-LABEL: sil [ossa] @multi_basic_block_with_loads_copy_and_take_3 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multi_basic_block_with_loads_copy_and_take_3'
sil [ossa] @multi_basic_block_with_loads_copy_and_take_3 : $@convention(thin) (@owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
br bb1
bb1:
%take = load [take] %1 : $*Klass
%copy = copy_value %take : $Klass
destroy_value %take : $Klass
dealloc_stack %1 : $*Klass
return %copy : $Klass
}
// CHECK-LABEL: sil [ossa] @multi_basic_block_with_store_assign :
// CHECK-NOT: alloc_stack
// CHECK: destroy_value %0 : $Klass
// CHECK-LABEL: } // end sil function 'multi_basic_block_with_store_assign'
sil [ossa] @multi_basic_block_with_store_assign : $@convention(thin) (@owned Klass, @owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass, %1: @owned $Klass):
%stk = alloc_stack $Klass
store %0 to [init] %stk : $*Klass
br bb1
bb1:
store %1 to [assign] %stk : $*Klass
%res = load [take] %stk : $*Klass
dealloc_stack %stk : $*Klass
return %res : $Klass
}
// CHECK-LABEL: sil [ossa] @multi_basic_block_with_phiarg :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: bb1:
// CHECK: br bb3(%1 : $Klass)
// CHECK-LABEL: bb2:
// CHECK: br bb3(%0 : $Klass)
// CHECK-LABEL: } // end sil function 'multi_basic_block_with_phiarg'
sil [ossa] @multi_basic_block_with_phiarg : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack $Klass
cond_br undef, bb1, bb2
bb1:
store %1 to [init] %stk : $*Klass
destroy_value %0 : $Klass
br bb3
bb2:
store %0 to [init] %stk : $*Klass
destroy_value %1 : $Klass
br bb3
bb3:
%val = load [take] %stk : $*Klass
destroy_value %val : $Klass
dealloc_stack %stk : $*Klass
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @multi_asi_basic_block_with_phiarg :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: bb1:
// CHECK: br bb3(%0 : $Klass, %1 : $Klass)
// CHECK-LABEL: bb2:
// CHECK: br bb3(%1 : $Klass, %0 : $Klass)
// CHECK-LABEL: } // end sil function 'multi_asi_basic_block_with_phiarg'
sil [ossa] @multi_asi_basic_block_with_phiarg : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk1 = alloc_stack $Klass
%stk2 = alloc_stack $Klass
cond_br undef, bb1, bb2
bb1:
store %1 to [init] %stk1 : $*Klass
store %0 to [init] %stk2 : $*Klass
br bb3
bb2:
store %1 to [init] %stk2 : $*Klass
store %0 to [init] %stk1 : $*Klass
br bb3
bb3:
%val1 = load [take] %stk1 : $*Klass
destroy_value %val1 : $Klass
%val2 = load [take] %stk2 : $*Klass
destroy_value %val2 : $Klass
dealloc_stack %stk2 : $*Klass
dealloc_stack %stk1 : $*Klass
%res = tuple ()
return %res : $()
}
// Test to check no dead args are passed to bb3 as phi arg
// CHECK-LABEL: sil [ossa] @multi_basic_block_stack_deallocated_phiarg :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK-LABEL: } // end sil function 'multi_basic_block_stack_deallocated_phiarg'
sil [ossa] @multi_basic_block_stack_deallocated_phiarg : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%stk = alloc_stack $Klass
cond_br undef, bb1, bb2
bb1:
dealloc_stack %stk : $*Klass
destroy_value %0 : $Klass
br bb3
bb2:
store %0 to [init] %stk : $*Klass
%val = load [take] %stk : $*Klass
dealloc_stack %stk : $*Klass
destroy_value %val : $Klass
br bb3
bb3:
%res = tuple ()
return %res : $()
}
// Test to check no dead args are passed to bb3 as phi arg
// CHECK-LABEL: sil [ossa] @multi_asi_basic_block_stack_deallocated_phiarg :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK-LABEL: } // end sil function 'multi_asi_basic_block_stack_deallocated_phiarg'
sil [ossa] @multi_asi_basic_block_stack_deallocated_phiarg : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk1 = alloc_stack $Klass
%stk2 = alloc_stack $Klass
cond_br undef, bb1, bb2
bb1:
dealloc_stack %stk2 : $*Klass
dealloc_stack %stk1 : $*Klass
destroy_value %0 : $Klass
destroy_value %1 : $Klass
br bb3
bb2:
store %0 to [init] %stk1 : $*Klass
%val1 = load [take] %stk1 : $*Klass
store %1 to [init] %stk2 : $*Klass
%val2 = load [take] %stk2 : $*Klass
destroy_value %val1 : $Klass
destroy_value %val2 : $Klass
dealloc_stack %stk2 : $*Klass
dealloc_stack %stk1 : $*Klass
br bb3
bb3:
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @multi_basic_block_destroyed_last_stored_val_phiarg :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: bb3:
// CHECK-LABEL: } // end sil function 'multi_basic_block_destroyed_last_stored_val_phiarg'
sil [ossa] @multi_basic_block_destroyed_last_stored_val_phiarg : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
%stk = alloc_stack $Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %0 : $Klass
br bb3
bb2:
store %0 to [init] %stk : $*Klass
%val = load [take] %stk : $*Klass
destroy_value %val : $Klass
br bb3
bb3:
dealloc_stack %stk : $*Klass
%res = tuple ()
return %res : $()
}
// 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) (@owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass):
%1 = alloc_stack $Klass
store %0 to [init] %1 : $*Klass
debug_value %1 : $*Klass, expr op_deref
%2 = load [take] %1 : $*Klass
dealloc_stack %1 : $*Klass
return %2 : $Klass
}
// CHECK-LABEL: sil [ossa] @mem2reg_struct_addr :
// CHECK-NOT: alloc_stack
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $SmallCodesizeStruct
// CHECK: [[ELE:%.*]] = struct_extract [[BORROW]]
// CHECK: [[COPY:%.*]] = copy_value [[ELE]] : $Klass
// CHECK: end_borrow [[BORROW]] : $SmallCodesizeStruct
// CHECK: return [[COPY]]
// CHECK-LABEL: } // end sil function 'mem2reg_struct_addr'
sil [ossa] @mem2reg_struct_addr : $@convention(thin) (@owned SmallCodesizeStruct) -> @owned Klass {
bb0(%0 : @owned $SmallCodesizeStruct):
%1 = alloc_stack $SmallCodesizeStruct
store %0 to [init] %1 : $*SmallCodesizeStruct
%2 = struct_element_addr %1 : $*SmallCodesizeStruct, #SmallCodesizeStruct.cls1
%3 = load [copy] %2 : $*Klass
destroy_addr %1 : $*SmallCodesizeStruct
dealloc_stack %1 : $*SmallCodesizeStruct
return %3 : $Klass
}
// SILMem2Reg is disabled when there is a load [take] with struct_element_addr/tuple_element_addr
// CHECK-LABEL: sil [ossa] @mem2reg_struct_addr_load_take :
// CHECK: alloc_stack
// CHECK-LABEL: } // end sil function 'mem2reg_struct_addr_load_take'
sil [ossa] @mem2reg_struct_addr_load_take : $@convention(thin) (@owned WrapperStruct) -> () {
bb0(%0 : @owned $WrapperStruct):
%1 = alloc_stack $WrapperStruct
store %0 to [init] %1 : $*WrapperStruct
%2 = struct_element_addr %1 : $*WrapperStruct, #WrapperStruct.cls
%3 = load [take] %2 : $*Klass
destroy_value %3 : $Klass
dealloc_stack %1 : $*WrapperStruct
%tup = tuple ()
return %tup : $()
}
// CHECK-LABEL: sil [ossa] @mem2reg_tuple_addr :
// CHECK-NOT: alloc_stack
// CHECK: [[TUP:%.*]] = tuple (%0 : $Klass, %1 : $Klass)
// CHECK: [[BORROW:%.*]] = begin_borrow [[TUP]] : $(Klass, Klass)
// CHECK: [[ELE:%.*]] = tuple_extract [[BORROW]]
// CHECK: [[COPY:%.*]] = copy_value [[ELE]] : $Klass
// CHECK: end_borrow [[BORROW]] : $(Klass, Klass)
// CHECK: return [[COPY]]
// CHECK-LABEL: } // end sil function 'mem2reg_tuple_addr'
sil [ossa] @mem2reg_tuple_addr : $@convention(thin) (@owned Klass, @owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack $(Klass, Klass)
%2 = tuple (%0 : $Klass, %1 : $Klass)
store %2 to [init] %stk : $*(Klass, Klass)
%4 = tuple_element_addr %stk : $*(Klass, Klass), 0
%5 = load [copy] %4 : $*Klass
destroy_addr %stk : $*(Klass, Klass)
dealloc_stack %stk : $*(Klass, Klass)
return %5 : $Klass
}
// 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'
// 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 $Klass
%local = alloc_ref $Klass
store %local to [init] %0 : $*Klass
// CHECK-NOT: debug_value {{.*}} expr op_deref
debug_value %0 : $*Klass, expr op_deref
destroy_addr %0 : $*Klass
// CHECK-NOT: dealloc_stack
dealloc_stack %0 : $*Klass
%1 = tuple ()
return %1 : $()
}
// CHECK-LABEL: } // end sil function 'no_real_uses'
// CHECK-LABEL: sil [ossa] @half_trivial
// CHECK: destructure_tuple %0
// CHECK-NEXT: destroy_value
// CHECK-NEXT: tuple
// CHECK-LABEL: } // end sil function 'half_trivial'
sil [ossa] @half_trivial : $@convention(thin) (@owned (Builtin.BridgeObject, Builtin.Int32)) -> () {
bb0(%0 : @owned $(Builtin.BridgeObject, Builtin.Int32)):
%1 = alloc_stack $(Builtin.BridgeObject, Builtin.Int32)
store %0 to [init] %1 : $*(Builtin.BridgeObject, Builtin.Int32)
%3 = load [copy] %1 : $*(Builtin.BridgeObject, Builtin.Int32)
destroy_value %3 : $(Builtin.BridgeObject, Builtin.Int32)
destroy_addr %1 : $*(Builtin.BridgeObject, Builtin.Int32)
dealloc_stack %1 : $*(Builtin.BridgeObject, Builtin.Int32)
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multiple_debug_value :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multiple_debug_value'
sil [ossa] @multiple_debug_value : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
debug_value %0 : $Klass
%2 = alloc_stack $Klass
store %0 to [init] %2 : $*Klass
debug_value %2 : $*Klass, expr op_deref
%5 = load [take] %2 : $*Klass
destroy_value %5 : $Klass
dealloc_stack %2 : $*Klass
%7 = tuple ()
return %7 : $()
}
// CHECK-LABEL: sil [ossa] @multi_basic_block_bug1 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multi_basic_block_bug1'
sil [ossa] @multi_basic_block_bug1 : $@convention(thin) (@owned Klass, @owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk1 = alloc_stack $Klass
store %0 to [init] %stk1 : $*Klass
cond_br undef, bb1, bb2
bb1:
%new1 = load [take] %stk1 : $*Klass
destroy_value %1 : $Klass
dealloc_stack %stk1 : $*Klass
br bbret(%new1 : $Klass)
bb2:
store %1 to [assign] %stk1 : $*Klass
%new2 = load [take] %stk1 : $*Klass
dealloc_stack %stk1 : $*Klass
br bbret(%new2 : $Klass)
bbret(%new : @owned $Klass):
return %new : $Klass
}
// CHECK-LABEL: sil [ossa] @multi_basic_block_bug2 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'multi_basic_block_bug2'
sil [ossa] @multi_basic_block_bug2 : $@convention(thin) (@owned Klass, @owned Klass) -> @owned Klass {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk1 = alloc_stack $Klass
store %0 to [init] %stk1 : $*Klass
cond_br undef, bb1, bb2
bb1:
%new1 = load [take] %stk1 : $*Klass
destroy_value %1 : $Klass
br bbret(%new1 : $Klass)
bb2:
store %1 to [assign] %stk1 : $*Klass
%new2 = load [take] %stk1 : $*Klass
br bbret(%new2 : $Klass)
bbret(%new : @owned $Klass):
dealloc_stack %stk1 : $*Klass
return %new : $Klass
}
// CHECK-LABEL: sil [ossa] @test_dynamiclifetime1 :
// CHECK: alloc_stack [dynamic_lifetime]
// CHECK-LABEL: } // end sil function 'test_dynamiclifetime1'
sil [ossa] @test_dynamiclifetime1 : $@convention(thin) () -> () {
bb0:
%2 = alloc_stack $Builtin.Int1
%3 = alloc_stack [dynamic_lifetime] $NonTrivialStruct
%4 = integer_literal $Builtin.Int1, 0
store %4 to [trivial] %2 : $*Builtin.Int1
cond_br undef, bb1, bb2
bb1:
br bb3
bb2:
%func = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%val = apply %func() : $@convention(thin) () -> @owned NonTrivialStruct
%27 = integer_literal $Builtin.Int1, -1
store %27 to [trivial] %2 : $*Builtin.Int1
store %val to [init] %3 : $*NonTrivialStruct
br bb3
bb3:
%32 = load [trivial] %2 : $*Builtin.Int1
cond_br %32, bb4, bb5
bb4:
%34 = load [take] %3 : $*NonTrivialStruct
destroy_value %34 : $NonTrivialStruct
br bb6
bb5:
br bb6
bb6:
dealloc_stack %3 : $*NonTrivialStruct
dealloc_stack %2 : $*Builtin.Int1
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @test_dynamiclifetime2 :
// CHECK: alloc_stack [dynamic_lifetime]
// CHECK-LABEL: } // end sil function 'test_dynamiclifetime2'
sil [ossa] @test_dynamiclifetime2 : $@convention(thin) () -> () {
bb0:
%2 = alloc_stack $Builtin.Int1
%3 = alloc_stack [dynamic_lifetime] $NonTrivialStruct
%4 = integer_literal $Builtin.Int1, 0
store %4 to [trivial] %2 : $*Builtin.Int1
%func1 = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%val1 = apply %func1() : $@convention(thin) () -> @owned NonTrivialStruct
store %val1 to [init] %3 : $*NonTrivialStruct
%ld1 = load [take] %3 : $*NonTrivialStruct
%func2 = function_ref @take_nontrivialstruct : $@convention(thin) (@owned NonTrivialStruct) -> ()
apply %func2(%ld1) : $@convention(thin) (@owned NonTrivialStruct) -> ()
cond_br undef, bb1, bb2
bb1:
br bb3
bb2:
%val = apply %func1() : $@convention(thin) () -> @owned NonTrivialStruct
%27 = integer_literal $Builtin.Int1, -1
store %27 to [trivial] %2 : $*Builtin.Int1
store %val to [init] %3 : $*NonTrivialStruct
br bb3
bb3:
%32 = load [trivial] %2 : $*Builtin.Int1
cond_br %32, bb4, bb5
bb4:
%ld2 = load [take] %3 : $*NonTrivialStruct
destroy_value %ld2 : $NonTrivialStruct
br bb6
bb5:
br bb6
bb6:
dealloc_stack %3 : $*NonTrivialStruct
dealloc_stack %2 : $*Builtin.Int1
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @test_deadphi1 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'test_deadphi1'
sil [ossa] @test_deadphi1 : $@convention(thin) () -> () {
bb0:
br bb1
bb1:
cond_br undef, bb1a, bb6
bb1a:
br bb2
bb2:
%stk = alloc_stack $NonTrivialStruct
cond_br undef, bb3, bb4
bb3:
%func = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%val = apply %func() : $@convention(thin) () -> @owned NonTrivialStruct
store %val to [init] %stk : $*NonTrivialStruct
%lval1 = load [copy] %stk : $*NonTrivialStruct
destroy_value %lval1 : $NonTrivialStruct
%lval2 = load [take] %stk : $*NonTrivialStruct
destroy_value %lval2 : $NonTrivialStruct
dealloc_stack %stk : $*NonTrivialStruct
cond_br undef, bb3a, bb3b
bb3a:
br bb1
bb3b:
br bb5
bb4:
dealloc_stack %stk : $*NonTrivialStruct
unreachable
bb5:
br bb2
bb6:
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @test_deadphi2 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'test_deadphi2'
sil [ossa] @test_deadphi2 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $NonTrivialStruct
br bb1
bb1:
cond_br undef, bb2, bb3
bb2:
%3 = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%4 = apply %3() : $@convention(thin) () -> @owned NonTrivialStruct
store %4 to [init] %0 : $*NonTrivialStruct
cond_br undef, bb4, bb5
bb3:
dealloc_stack %0 : $*NonTrivialStruct
br bb7
bb4:
%lval1 = load [take] %0 : $*NonTrivialStruct
destroy_value %lval1 : $NonTrivialStruct
dealloc_stack %0 : $*NonTrivialStruct
br bb7
bb5:
%lval2 = load [take] %0 : $*NonTrivialStruct
destroy_value %lval2 : $NonTrivialStruct
dealloc_stack %0 : $*NonTrivialStruct
br bb7
bb6:
%17 = tuple ()
return %17 : $()
bb7:
br bb6
}
// CHECK-LABEL: sil [ossa] @test_deadphi3 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'test_deadphi3'
sil [ossa] @test_deadphi3 : $@convention(thin) (@owned NonTrivialEnum) -> () {
bb0(%0 : @owned $NonTrivialEnum):
%1 = alloc_stack $NonTrivialStruct
switch_enum %0 : $NonTrivialEnum, case #NonTrivialEnum.some1!enumelt: bb1, case #NonTrivialEnum.some2!enumelt: bb5
bb1(%3 : @owned $Klass):
destroy_value %3 : $Klass
%5 = function_ref @get_optionalnontrivialstruct : $@convention(thin) () -> @owned FakeOptional<NonTrivialStruct>
%6 = apply %5() : $@convention(thin) () -> @owned FakeOptional<NonTrivialStruct>
switch_enum %6 : $FakeOptional<NonTrivialStruct>, case #FakeOptional.some!enumelt: bb4, case #FakeOptional.none!enumelt: bb2
bb2:
br bb3
bb3:
unreachable
bb4(%10 : @owned $NonTrivialStruct):
store %10 to [init] %1 : $*NonTrivialStruct
br bb9
bb5(%13 : @owned $NonTrivialStruct):
destroy_value %13 : $NonTrivialStruct
%15 = function_ref @get_optionalnontrivialstruct : $@convention(thin) () -> @owned FakeOptional<NonTrivialStruct>
%16 = apply %15() : $@convention(thin) () -> @owned FakeOptional<NonTrivialStruct>
switch_enum %16 : $FakeOptional<NonTrivialStruct>, case #FakeOptional.some!enumelt: bb8, case #FakeOptional.none!enumelt: bb6
bb6:
br bb7
bb7:
unreachable
bb8(%20 : @owned $NonTrivialStruct):
store %20 to [init] %1 : $*NonTrivialStruct
br bb9
bb9:
%23 = function_ref @get_nontrivialenum : $@convention(thin) () -> @owned NonTrivialEnum
%24 = apply %23() : $@convention(thin) () -> @owned NonTrivialEnum
switch_enum %24 : $NonTrivialEnum, case #NonTrivialEnum.some1!enumelt: bb10, case #NonTrivialEnum.some2!enumelt: bb11
bb10(%26 : @owned $Klass):
%27 = load [copy] %1 : $*NonTrivialStruct
destroy_value %27 : $NonTrivialStruct
destroy_value %26 : $Klass
br bb12
bb11(%31 : @owned $NonTrivialStruct):
%32 = load [copy] %1 : $*NonTrivialStruct
destroy_value %32 : $NonTrivialStruct
destroy_value %31 : $NonTrivialStruct
br bb12
bb12:
%36 = load [take] %1 : $*NonTrivialStruct
destroy_value %36 : $NonTrivialStruct
dealloc_stack %1 : $*NonTrivialStruct
%39 = tuple ()
return %39 : $()
}
sil @return_optional_or_error : $@convention(thin) () -> (@owned KlassOptional, @error Error)
// CHECK-LABEL: sil [ossa] @test_deadphi4 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'test_deadphi4'
sil [ossa] @test_deadphi4 : $@convention(thin) (@owned KlassOptional) -> () {
bb0(%0 : @owned $KlassOptional):
%stk = alloc_stack $KlassOptional
switch_enum %0 : $KlassOptional, case #KlassOptional.some!enumelt: bb2, case #KlassOptional.none!enumelt: bb1
bb1:
dealloc_stack %stk : $*KlassOptional
br bb7
bb2(%some : @owned $Klass):
destroy_value %some : $Klass
%19 = function_ref @return_optional_or_error : $@convention(thin) () -> (@owned KlassOptional, @error Error)
try_apply %19() : $@convention(thin) () -> (@owned KlassOptional, @error Error), normal bb3, error bb8
bb3(%callresult : @owned $KlassOptional):
store %callresult to [init] %stk : $*KlassOptional
%29 = load [take] %stk : $*KlassOptional
switch_enum %29 : $KlassOptional, case #KlassOptional.some!enumelt: bb5, case #KlassOptional.none!enumelt: bb4
bb4:
dealloc_stack %stk : $*KlassOptional
br bb7
bb5(%33 : @owned $Klass):
destroy_value %33 : $Klass
dealloc_stack %stk : $*KlassOptional
br bb6
bb6:
%39 = tuple ()
return %39 : $()
bb7:
br bb6
bb8(%err : @owned $Error):
unreachable
}
// CHECK-LABEL: sil [ossa] @test_deadphi5 :
// CHECK-NOT: alloc_stack
// CHECK-LABEL: } // end sil function 'test_deadphi5'
sil [ossa] @test_deadphi5 : $@convention(thin) () -> () {
bb0:
%stk = alloc_stack $NonTrivialStruct
cond_br undef, bb2, bb1
bb1:
%func1 = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%val1 = apply %func1() : $@convention(thin) () -> @owned NonTrivialStruct
store %val1 to [init] %stk : $*NonTrivialStruct
br bb5
bb2:
%func2 = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
%val2 = apply %func2() : $@convention(thin) () -> @owned NonTrivialStruct
store %val2 to [init] %stk : $*NonTrivialStruct
cond_br undef, bb3, bb4
bb3:
br bb5
bb4:
%lval1 = load [take] %stk : $*NonTrivialStruct
destroy_value %lval1 : $NonTrivialStruct
dealloc_stack %stk : $*NonTrivialStruct
br bb9
bb5:
cond_br undef, bb6, bb7
bb6:
%lval2 = load [take] %stk : $*NonTrivialStruct
destroy_value %lval2 : $NonTrivialStruct
br bb8
bb7:
%lval3 = load [take] %stk : $*NonTrivialStruct
destroy_value %lval3 : $NonTrivialStruct
br bb8
bb8:
dealloc_stack %stk : $*NonTrivialStruct
br bb9
bb9:
%res = tuple ()
return %res : $()
}
// Test that a load [take] of an unchecked_addr_cast doesn't get promoted.
//
// CHECK-LABEL: sil [ossa] @load_take_unchecked_addr_cast : {{.*}} {
// CHECK: load [take]
// CHECK-LABEL: } // end sil function 'load_take_unchecked_addr_cast'
sil [ossa] @load_take_unchecked_addr_cast : $@convention(thin) (@guaranteed AnyObject) -> () {
entry(%instance : @guaranteed $AnyObject):
%copy = copy_value %instance : $AnyObject
%storage = alloc_stack $AnyObject
store %copy to [init] %storage : $*AnyObject
%cast_addr = unchecked_addr_cast %storage : $*AnyObject to $*Klass
%value = load [take] %cast_addr : $*Klass
dealloc_stack %storage : $*AnyObject
destroy_value %value : $Klass
%retval = tuple ()
return %retval : $()
}
// Don't bail if the original address is destroyed even if we see a cast.
//
// CHECK-LABEL: sil [ossa] @destroy_original_storage : {{.*}} {
// CHECK: destroy_value
// CHECK-LABEL: } // end sil function 'destroy_original_storage'
sil [ossa] @destroy_original_storage : $@convention(thin) (@guaranteed AnyObject) -> () {
entry(%instance : @guaranteed $AnyObject):
%copy = copy_value %instance : $AnyObject
%storage = alloc_stack $AnyObject
store %copy to [init] %storage : $*AnyObject
%cast_addr = unchecked_addr_cast %storage : $*AnyObject to $*Klass
%value = load [copy] %cast_addr : $*Klass
destroy_addr %storage : $*AnyObject
dealloc_stack %storage : $*AnyObject
destroy_value %value : $Klass
%retval = tuple ()
return %retval : $()
}
// Bail if the address produced by an unchecked_addr_cast is destroyed.
//
// CHECK-LABEL: sil [ossa] @destroy_addr_unchecked_addr_cast : {{.*}} {
// CHECK: unchecked_addr_cast
// CHECK: load [copy]
// CHECK-LABEL: } // end sil function 'destroy_addr_unchecked_addr_cast'
sil [ossa] @destroy_addr_unchecked_addr_cast : $@convention(thin) (@guaranteed AnyObject) -> () {
entry(%instance : @guaranteed $AnyObject):
%copy = copy_value %instance : $AnyObject
%storage = alloc_stack $AnyObject
store %copy to [init] %storage : $*AnyObject
%cast_addr = unchecked_addr_cast %storage : $*AnyObject to $*Klass
%value = load [copy] %cast_addr : $*Klass
destroy_addr %cast_addr : $*Klass
dealloc_stack %storage : $*AnyObject
destroy_value %value : $Klass
%retval = tuple ()
return %retval : $()
}
// Bail if there's a load [take] of one of multiple non-trivial fields.
//
// CHECK-LABEL: sil [ossa] @load_take_one_of_two_nontrivial_struct_fields : {{.*}} {
// CHECK: load [take]
// CHECK: destroy_addr
// CHECK-LABEL: } // end sil function 'load_take_one_of_two_nontrivial_struct_fields'
sil [ossa] @load_take_one_of_two_nontrivial_struct_fields : $@convention(thin) (@guaranteed S) -> () {
entry(%instance : @guaranteed $S):
%copy = copy_value %instance : $S
%storage = alloc_stack $S
store %copy to [init] %storage : $*S
%v1_addr = struct_element_addr %storage : $*S, #S.v1
%cast_addr = unchecked_addr_cast %v1_addr : $*AnyObject to $*Klass
%value = load [take] %cast_addr : $*Klass
%v2_addr = struct_element_addr %storage : $*S, #S.v2
destroy_addr %v2_addr : $*AnyObject
//destroy_addr %storage : $*S
dealloc_stack %storage : $*S
destroy_value %value : $Klass
%retval = tuple ()
return %retval : $()
}
// Don't bail if we happen to see an unchecked_addr_cast but then load [take]
// the original address.
//
// CHECK-LABEL: sil [ossa] @load_take_original_despite_cast : {{.*}} {
// CHECK: unchecked_bitwise_cast
// CHECK: destroy_value
// CHECK-LABEL: } // end sil function 'load_take_original_despite_cast'
sil [ossa] @load_take_original_despite_cast : $@convention(thin) (@owned AnyObject) -> () {
entry(%instance : @owned $AnyObject):
%74 = alloc_stack $AnyObject
store %instance to [init] %74 : $*AnyObject
%76 = unchecked_addr_cast %74 : $*AnyObject to $*UInt8
%77 = load [trivial] %76 : $*UInt8
%79 = load [take] %74 : $*AnyObject
destroy_value %79 : $AnyObject
dealloc_stack %74 : $*AnyObject
%82 = tuple ()
return %82 : $()
}
// CHECK-LABEL: sil [ossa] @test_enum_store_borrow_none :
// CHECK: alloc_stack
// CHECK-NOT: alloc_stack
// CHECK: dealloc_stack
// CHECK-LABEL: } // end sil function 'test_enum_store_borrow_none'
sil [ossa] @test_enum_store_borrow_none : $@convention(thin) () -> () {
bb0:
%1 = alloc_stack [lexical] $FakeOptional<Klass>
%none = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
%2 = store_borrow %none to %1 : $*FakeOptional<Klass>
%3 = alloc_stack $FakeOptional<Klass>
%4 = load [copy] %2 : $*FakeOptional<Klass>
store %4 to [init] %3 : $*FakeOptional<Klass>
switch_enum_addr %3 : $*FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2
bb1:
%7 = unchecked_take_enum_data_addr %3 : $*FakeOptional<Klass>, #FakeOptional.some!enumelt
%8 = load [take] %7 : $*Klass
destroy_value %8 : $Klass
dealloc_stack %3 : $*FakeOptional<Klass>
br bb3
bb2:
dealloc_stack %3 : $*FakeOptional<Klass>
br bb3
bb3:
end_borrow %2 : $*FakeOptional<Klass>
dealloc_stack %1 : $*FakeOptional<Klass>
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: sil [ossa] @test_enum_store_none :
// CHECK: alloc_stack
// CHECK-NOT: alloc_stack
// CHECK: dealloc_stack
// CHECK-LABEL: } // end sil function 'test_enum_store_none'
sil [ossa] @test_enum_store_none : $@convention(thin) () -> () {
bb0:
%1 = alloc_stack [lexical] $FakeOptional<Klass>
%none = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
store %none to [init] %1 : $*FakeOptional<Klass>
%3 = alloc_stack $FakeOptional<Klass>
%4 = load [copy] %1 : $*FakeOptional<Klass>
store %4 to [init] %3 : $*FakeOptional<Klass>
switch_enum_addr %3 : $*FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2
bb1:
%7 = unchecked_take_enum_data_addr %3 : $*FakeOptional<Klass>, #FakeOptional.some!enumelt
%8 = load [take] %7 : $*Klass
destroy_value %8 : $Klass
dealloc_stack %3 : $*FakeOptional<Klass>
br bb3
bb2:
dealloc_stack %3 : $*FakeOptional<Klass>
br bb3
bb3:
destroy_addr %1 : $*FakeOptional<Klass>
dealloc_stack %1 : $*FakeOptional<Klass>
%t = tuple ()
return %t : $()
}
|