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
|
// RUN: %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
class C {}
sil @getOwned : $@convention(thin) () -> @owned C
sil @barrier : $@convention(thin) () -> ()
sil [ossa] @getC : $@convention(thin) () -> @owned C
sil [ossa] @borrowC : $@convention(thin) (@guaranteed C) -> ()
sil [ossa] @takeC : $@convention(thin) (@owned C) -> ()
struct S {}
@_moveOnly struct MoS {}
@_moveOnly struct MoE {}
// CHECK-LABEL: begin running test 1 of 1 on fn: canonicalize-ossa-lifetime with: true, true, true, @trace
// CHECK-LABEL: end running test 1 of 1 on fn: canonicalize-ossa-lifetime with: true, true, true, @trace
sil [ossa] @fn : $@convention(thin) () -> () {
entry:
specify_test "canonicalize-ossa-lifetime true true true @trace"
%getC = function_ref @getC : $@convention(thin) () -> @owned C
%c = apply %getC() : $@convention(thin) () -> @owned C
debug_value [trace] %c : $C
%borrowC = function_ref @borrowC : $@convention(thin) (@guaranteed C) -> ()
apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> ()
debug_value %c : $C
destroy_value %c : $C
%retval = tuple ()
return %retval : $()
}
// When access scopes are respected, the lifetime which previously extended
// beyond the access scope still extends beyond it.
// CHECK-LABEL: begin running test 1 of 2 on retract_value_lifetime_into_access_scope_when_access_scopes_not_respected: canonicalize-ossa-lifetime with: true, false, true, @trace
// CHECK-LABEL: sil [ossa] @retract_value_lifetime_into_access_scope_when_access_scopes_not_respected {{.*}} {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] :
// CHECK: [[INSTANCE:%[^,]+]] = apply
// CHECK: [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
// CHECK: [[ACCESS:%[^,]+]] = begin_access [modify] [static] [[ADDR]]
// CHECK: store [[COPY]] to [init] [[ACCESS]]
// CHECK: end_access [[ACCESS]]
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'retract_value_lifetime_into_access_scope_when_access_scopes_not_respected'
// CHECK-LABEL: end running test 1 of 2 on retract_value_lifetime_into_access_scope_when_access_scopes_not_respected: canonicalize-ossa-lifetime with: true, false, true, @trace
// When access scopes are not respected, the lifetime which previously extended
// beyond the access scope is retracted into the scope.
// CHECK-LABEL: begin running test 2 of 2 on retract_value_lifetime_into_access_scope_when_access_scopes_not_respected: canonicalize-ossa-lifetime with: true, false, false, @trace
// CHECK-LABEL: sil [ossa] @retract_value_lifetime_into_access_scope_when_access_scopes_not_respected {{.*}} {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] :
// CHECK: [[INSTANCE:%[^,]+]] = apply
// CHECK: [[ACCESS:%[^,]+]] = begin_access [modify] [static] [[ADDR]]
// CHECK: store [[INSTANCE]] to [init] [[ACCESS]]
// CHECK: end_access [[ACCESS]]
// CHECK-LABEL: } // end sil function 'retract_value_lifetime_into_access_scope_when_access_scopes_not_respected'
// CHECK-LABEL: end running test 2 of 2 on retract_value_lifetime_into_access_scope_when_access_scopes_not_respected: canonicalize-ossa-lifetime with: true, false, false, @trace
sil [ossa] @retract_value_lifetime_into_access_scope_when_access_scopes_not_respected : $@convention(thin) () -> @out C {
bb0(%addr : $*C):
%instance = apply undef() : $@convention(thin) () -> @owned C
debug_value [trace] %instance : $C
// respect access scopes
// VVVV
specify_test "canonicalize-ossa-lifetime true false true @trace"
specify_test "canonicalize-ossa-lifetime true false false @trace"
// ^^^^^
// respect access scopes
%copy = copy_value %instance : $C
%access = begin_access [modify] [static] %addr : $*C
store %copy to [init] %access : $*C
end_access %access : $*C
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test 1 of 1 on reuse_destroy_after_barrier_phi: canonicalize-ossa-lifetime with: true, false, true, @trace
// CHECK-LABEL: sil [ossa] @reuse_destroy_after_barrier_phi : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
// CHECK: {{bb[0-9]+}}({{%[^,]+}}
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'reuse_destroy_after_barrier_phi'
// CHECK-LABEL: end running test 1 of 1 on reuse_destroy_after_barrier_phi: canonicalize-ossa-lifetime with: true, false, true, @trace
sil [ossa] @reuse_destroy_after_barrier_phi : $@convention(thin) (@owned C) -> @owned C {
entry(%instance : @owned $C):
debug_value [trace] %instance : $C
specify_test "canonicalize-ossa-lifetime true false true @trace"
%get = function_ref @getOwned : $@convention(thin) () -> @owned C
cond_br undef, through, loop
through:
%4 = copy_value %instance : $C
br exit(%4 : $C)
loop:
%other = apply %get() : $@convention(thin) () -> @owned C
br exit(%other : $C)
exit(%out : @owned $C):
destroy_value %instance : $C
return %out : $C
}
// CHECK-LABEL: begin running test 1 of 1 on store_arg_to_out_addr: canonicalize-ossa-lifetime with: true, false, true, @trace
// CHECK-LABEL: sil [ossa] @store_arg_to_out_addr : $@convention(thin) (@owned C) -> @out C {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] : $*C, [[INSTANCE:%[^,]+]] :
// CHECK: store [[INSTANCE]] to [init] [[ADDR]]
// CHECK-LABEL: } // end sil function 'store_arg_to_out_addr'
// CHECK-LABEL: end running test 1 of 1 on store_arg_to_out_addr: canonicalize-ossa-lifetime with: true, false, true, @trace
sil [ossa] @store_arg_to_out_addr : $@convention(thin) (@owned C) -> @out C {
bb0(%0 : $*C, %instance : @owned $C):
debug_value [trace] %instance : $C
specify_test "canonicalize-ossa-lifetime true false true @trace"
%copy = copy_value %instance : $C
store %copy to [init] %0 : $*C
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test 1 of 1 on store_arg_to_out_addr_with_barrier: canonicalize-ossa-lifetime with: true, false, true, @trace
// CHECK-LABEL: sil [ossa] @store_arg_to_out_addr_with_barrier : $@convention(thin) (@owned C) -> @out C {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] : $*C, [[INSTANCE:%[^,]+]] :
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
// CHECK: store [[COPY]] to [init] [[ADDR]]
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'store_arg_to_out_addr_with_barrier'
// CHECK-LABEL: end running test 1 of 1 on store_arg_to_out_addr_with_barrier: canonicalize-ossa-lifetime with: true, false, true, @trace
sil [ossa] @store_arg_to_out_addr_with_barrier : $@convention(thin) (@owned C) -> @out C {
bb0(%0 : $*C, %instance : @owned $C):
%barrier = function_ref @barrier : $@convention(thin) () -> ()
debug_value [trace] %instance : $C
specify_test "canonicalize-ossa-lifetime true false true @trace"
%copy = copy_value %instance : $C
store %copy to [init] %0 : $*C
apply %barrier() : $@convention(thin) () -> ()
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// Don't crash on an adjacent phi with an incoming undef.
sil [ossa] @adjacent_phi_with_incoming_undef : $@convention(thin) () -> () {
entry:
%getC = function_ref @getOwned : $@convention(thin) () -> @owned C
%c2 = apply %getC() : $@convention(thin) () -> @owned C
br right2(%c2 : $C)
right2(%c2p : @owned $C):
br exit(%c2p : $C, undef : $S)
exit(%phi : @owned $C, %typhi : $S):
debug_value [trace] %phi : $C
specify_test "canonicalize-ossa-lifetime true false true @trace"
destroy_value %phi : $C
%retval = tuple ()
return %retval : $()
}
sil @empty : $@convention(thin) () -> () {
[global: ]
bb0:
%0 = tuple ()
return %0 : $()
}
// Even though the apply of %empty is not a deinit barrier, verify that the
// destroy is not hoisted, because MoS is move-only.
// CHECK-LABEL: begin running test {{.*}} on dont_move_destroy_value_of_moveonly_struct: canonicalize-ossa-lifetime with: true, false, true, @argument
// CHECK-LABEL: sil [ossa] @dont_move_destroy_value_of_moveonly_struct : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
// CHECK: apply
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'dont_move_destroy_value_of_moveonly_struct'
// CHECK-LABEL: end running test {{.*}} on dont_move_destroy_value_of_moveonly_struct: canonicalize-ossa-lifetime with: true, false, true, @argument
sil [ossa] @dont_move_destroy_value_of_moveonly_struct : $@convention(thin) (@owned MoS) -> () {
entry(%instance : @owned $MoS):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%empty = function_ref @empty : $@convention(thin) () -> ()
apply %empty() : $@convention(thin) () -> ()
destroy_value %instance : $MoS
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test {{.*}} on dont_move_destroy_value_of_moveonly_enum: canonicalize-ossa-lifetime with: true, false, true, @argument
// CHECK-LABEL: sil [ossa] @dont_move_destroy_value_of_moveonly_enum : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
// CHECK: apply
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'dont_move_destroy_value_of_moveonly_enum'
// CHECK-LABEL: end running test {{.*}} on dont_move_destroy_value_of_moveonly_enum: canonicalize-ossa-lifetime with: true, false, true, @argument
sil [ossa] @dont_move_destroy_value_of_moveonly_enum : $@convention(thin) (@owned MoE) -> () {
entry(%instance : @owned $MoE):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%empty = function_ref @empty : $@convention(thin) () -> ()
apply %empty() : $@convention(thin) () -> ()
destroy_value %instance : $MoE
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test 1 of 1 on respect_boundary_edges_when_extending_to_deinit_barriers
// CHECK-LABEL: sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers : {{.*}} {
// CHECK: bb0([[INSTANCE:%[^,]+]] :
// CHECK: apply {{%[^,]+}}()
// CHECK: cond_br undef, [[DIE:bb[0-9]+]], [[DESTROY:bb[0-9]+]]
// CHECK: [[DIE]]:
// CHECK: unreachable
// CHECK: [[DESTROY]]:
// CHECK: destroy_value [[INSTANCE]] : $C
// CHECK: return
// CHECK-LABEL: } // end sil function 'respect_boundary_edges_when_extending_to_deinit_barriers'
// CHECK-LABEL: end running test 1 of 1 on respect_boundary_edges_when_extending_to_deinit_barriers
sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers : $@convention(thin) (@owned C) -> () {
entry(%instance : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%barrier = function_ref @barrier : $@convention(thin) () -> ()
apply %barrier() : $@convention(thin) () -> ()
cond_br undef, die, destroy
die:
unreachable
destroy:
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test {{.*}} on respect_boundary_edges_when_extending_to_deinit_barriers_2
// CHECK-LABEL: sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers_2 : {{.*}} {
// CHECK: bb0([[INSTANCE:%[^,]+]] :
// CHECK: apply
// CHECK: cond_br undef, [[DIE:bb[0-9]+]], [[DESTROY:bb[0-9]+]]
// CHECK: [[DIE]]:
// CHECK: apply
// CHECK: unreachable
// CHECK: [[DESTROY]]:
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'respect_boundary_edges_when_extending_to_deinit_barriers_2'
// CHECK-LABEL: end running test {{.*}} on respect_boundary_edges_when_extending_to_deinit_barriers_2
sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers_2 : $@convention(thin) (@owned C) -> () {
entry(%instance : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%barrier = function_ref @barrier : $@convention(thin) () -> ()
apply %barrier() : $@convention(thin) () -> ()
cond_br undef, die, destroy
die:
apply %barrier() : $@convention(thin) () -> ()
br rlydie
rlydie:
unreachable
destroy:
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test {{.*}} on respect_boundary_edges_when_extending_to_deinit_barriers_3
// CHECK-LABEL: sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers_3 : {{.*}} {
// CHECK: bb0([[INSTANCE:%[^,]+]] :
// CHECK: apply
// CHECK: cond_br undef, [[DIE:bb[0-9]+]], [[DESTROY:bb[0-9]+]]
// CHECK: [[DIE]]:
// CHECK: apply
// CHECK-NOT: destroy_value [[INSTANCE]]
// CHECK: unreachable
// CHECK: [[DESTROY]]:
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'respect_boundary_edges_when_extending_to_deinit_barriers_3'
// CHECK-LABEL: end running test {{.*}} on respect_boundary_edges_when_extending_to_deinit_barriers_3
sil [ossa] @respect_boundary_edges_when_extending_to_deinit_barriers_3 : $@convention(thin) (@owned C) -> () {
entry(%instance : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%barrier = function_ref @barrier : $@convention(thin) () -> ()
apply %barrier() : $@convention(thin) () -> ()
cond_br undef, die, destroy
die:
apply %barrier() : $@convention(thin) () -> ()
unreachable
destroy:
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// Verify that an explicit destroy_value which happens to be just before an
// unreachable isn't deleted if liveness extends to the previous instruction.
// CHECK-LABEL: begin running test 1 of 1 on respect_preexisting_destroy_values_when_extending_to_deinit_barriers
// CHECK-LABEL: sil [ossa] @respect_preexisting_destroy_values_when_extending_to_deinit_barriers : {{.*}} {
// CHECK: bb0([[INSTANCE:%[^,]+]] :
// CHECK: cond_br undef, [[DIE:bb[0-9]+]], [[DESTROY:bb[0-9]+]]
// CHECK: [[DIE]]:
// CHECK: apply {{%[^,]+}}()
// CHECK: destroy_value [[INSTANCE]] : $C
// CHECK: unreachable
// CHECK: [[DESTROY]]:
// CHECK: destroy_value [[INSTANCE]] : $C
// CHECK: return
// CHECK-LABEL: } // end sil function 'respect_preexisting_destroy_values_when_extending_to_deinit_barriers'
// CHECK-LABEL: end running test 1 of 1 on respect_preexisting_destroy_values_when_extending_to_deinit_barriers
sil [ossa] @respect_preexisting_destroy_values_when_extending_to_deinit_barriers : $@convention(thin) (@owned C) -> () {
entry(%instance : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
%barrier = function_ref @barrier : $@convention(thin) () -> ()
cond_br undef, die, destroy
die:
apply %barrier() : $@convention(thin) () -> ()
destroy_value %instance : $C
unreachable
destroy:
destroy_value %instance : $C
%retval = tuple ()
return %retval : $()
}
// (1) When no end is specified, the lifetime ends after the barrier.
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_1: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_1 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: [[C2:%[^,]+]] = copy_value [[C1]]
// CHECK: [[M:%[^,]+]] = move_value [[C2]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_1'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_1: canonicalize-ossa-lifetime
// (2) When the move_value is specified as a lexical-lifetime-end, the lifetime doesn't extend to the destroy.
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_1: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_1 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: [[M:%[^,]+]] = move_value [[C1]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: apply [[BARRIER]]()
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_1'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_1: canonicalize-ossa-lifetime
sil [ossa] @lexical_end_at_end_1 : $@convention(thin) (@owned C) -> () {
entry(%c1 : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
specify_test "canonicalize-ossa-lifetime true false true @argument %m"
%takeC = function_ref @takeC : $@convention(thin) (@owned C) -> ()
%barrier = function_ref @barrier : $@convention(thin) () -> ()
%c2 = copy_value %c1 : $C
%m = move_value %c2 : $C
apply %takeC(%m) : $@convention(thin) (@owned C) -> ()
apply %barrier() : $@convention(thin) () -> ()
destroy_value %c1 : $C
%retval = tuple ()
return %retval : $()
}
// (1) When no end is specified, the lifetime ends after the barrier.
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_2: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_2 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK: [[LEFT]]:
// CHECK: [[C2:%[^,]+]] = copy_value [[C1]]
// CHECK: [[M:%[^,]+]] = move_value [[C2]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br [[EXIT:bb[0-9]+]]
// CHECK: [[RIGHT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_2'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_2: canonicalize-ossa-lifetime
// (2) When the move_value is specified as a lexical-lifetime-end, the lifetime
// doesn't extend to the destroy. But it DOES extend beyond barriers in
// blocks where unaffected by the move_value.
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_2: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_2 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] : @owned $C):
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: cond_br undef, [[LEFT]], [[RIGHT]]
// CHECK: [[LEFT]]:
// CHECK: [[M:%[^,]+]] = move_value [[C1]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br [[EXIT]]
// CHECK: [[RIGHT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK: apply [[BARRIER]]()
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_2'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_2: canonicalize-ossa-lifetime
sil [ossa] @lexical_end_at_end_2 : $@convention(thin) (@owned C) -> () {
entry(%c1 : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
specify_test "canonicalize-ossa-lifetime true false true @argument %m"
%takeC = function_ref @takeC : $@convention(thin) (@owned C) -> ()
%barrier = function_ref @barrier : $@convention(thin) () -> ()
cond_br undef, left, right
left:
%c2 = copy_value %c1 : $C
%m = move_value %c2 : $C
apply %takeC(%m) : $@convention(thin) (@owned C) -> ()
br exit
right:
apply %barrier() : $@convention(thin) () -> ()
br exit
exit:
apply %barrier() : $@convention(thin) () -> ()
destroy_value %c1 : $C
%retval = tuple ()
return %retval : $()
}
// Check barriers on branching unconsumed paths are respected.
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_3: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_3 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT_TOP:bb[0-9]+]]
// CHECK: [[LEFT]]:
// CHECK: [[C2:%[^,]+]] = copy_value [[C1]]
// CHECK: [[M:%[^,]+]] = move_value [[C2]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br [[EXIT:bb[0-9]+]]
// CHECK: [[RIGHT_TOP]]:
// CHECK: cond_br undef, [[RIGHT_LEFT:bb[0-9]+]], [[RIGHT_RIGHT:bb[0-9]+]]
// CHECK: [[RIGHT_LEFT]]:
// CHECK: [[C2P:%[^,]+]] = copy_value [[C1]]
// CHECK: apply [[TAKE_C]]([[C2P]])
// CHECK: br [[RIGHT_BOTTOM:bb[0-9]+]]
// CHECK: [[RIGHT_RIGHT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[RIGHT_BOTTOM]]
// CHECK: [[RIGHT_BOTTOM]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_3'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_3: canonicalize-ossa-lifetime
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_3: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_3 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: cond_br undef, bb1, bb2
// CHECK: bb1:
// CHECK: [[M:%[^,]+]] = move_value [[C1]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br bb6
// CHECK: bb2:
// CHECK: cond_br undef, bb3, bb4
// CHECK: bb3:
// CHECK: [[C2P:%[^,]+]] = copy_value [[C1]]
// CHECK: apply [[TAKE_C]]([[C2P]])
// CHECK: br bb5
// CHECK: bb4:
// CHECK: apply [[BARRIER]]()
// CHECK: br bb5
// CHECK: bb5:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK: br bb6
// CHECK: bb6:
// CHECK: apply [[BARRIER]]()
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_3'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_3: canonicalize-ossa-lifetime
sil [ossa] @lexical_end_at_end_3 : $@convention(thin) (@owned C) -> () {
entry(%c1 : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
specify_test "canonicalize-ossa-lifetime true false true @argument %m"
%takeC = function_ref @takeC : $@convention(thin) (@owned C) -> ()
%barrier = function_ref @barrier : $@convention(thin) () -> ()
cond_br undef, left, right_top
left:
%c2 = copy_value %c1 : $C
%m = move_value %c2 : $C
apply %takeC(%m) : $@convention(thin) (@owned C) -> ()
br exit
right_top:
cond_br undef, right_left, right_right
right_left:
%c2p = copy_value %c1 : $C
apply %takeC(%c2p) : $@convention(thin) (@owned C) -> ()
br right_bottom
right_right:
apply %barrier() : $@convention(thin) () -> ()
br right_bottom
right_bottom:
apply %barrier() : $@convention(thin) () -> ()
br exit
exit:
apply %barrier() : $@convention(thin) () -> ()
destroy_value %c1 : $C
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_4: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_4 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT_TOP:bb[0-9]+]]
// CHECK: [[LEFT]]:
// CHECK: [[C2:%[^,]+]] = copy_value [[C1]]
// CHECK: [[M:%[^,]+]] = move_value [[C2]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br [[EXIT:bb[0-9]+]]
// CHECK: [[RIGHT_TOP]]:
// CHECK: cond_br undef, [[RIGHT_LEFT:bb[0-9]+]], [[RIGHT_RIGHT:bb[0-9]+]]
// CHECK: [[RIGHT_LEFT]]:
// CHECK: [[C2P:%[^,]+]] = copy_value [[C1]]
// CHECK: [[M2:%[^,]+]] = move_value [[C2P]]
// CHECK: apply [[TAKE_C]]([[M2]])
// CHECK: br [[RIGHT_BOTTOM:bb[0-9]+]]
// CHECK: [[RIGHT_RIGHT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[RIGHT_BOTTOM]]
// CHECK: [[RIGHT_BOTTOM]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_4'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_4: canonicalize-ossa-lifetime
// CHECK-LABEL: begin running test {{.*}} on lexical_end_at_end_4: canonicalize-ossa-lifetime
// CHECK-LABEL: sil [ossa] @lexical_end_at_end_4 : {{.*}} {
// CHECK: bb0([[C1:%[^,]+]] :
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC : $@convention(thin) (@owned C) -> ()
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier : $@convention(thin) () -> ()
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT_TOP:bb[0-9]+]]
// CHECK: [[LEFT]]:
// CHECK: [[M:%[^,]+]] = move_value [[C1]]
// CHECK: apply [[TAKE_C]]([[M]])
// CHECK: br [[EXIT:bb[0-9]+]]
// CHECK: [[RIGHT_TOP]]:
// CHECK: cond_br undef, [[RIGHT_LEFT:bb[0-9]+]], [[RIGHT_RIGHT:bb[0-9]+]]
// CHECK: [[RIGHT_LEFT]]:
// CHECK: [[M2:%[^,]+]] = move_value [[C1]]
// CHECK: apply [[TAKE_C]]([[M2]])
// CHECK: br [[RIGHT_BOTTOM:bb[0-9]+]]
// CHECK: [[RIGHT_RIGHT]]:
// CHECK: apply [[BARRIER]]()
// CHECK: destroy_value [[C1]]
// CHECK: br [[RIGHT_BOTTOM]]
// CHECK: [[RIGHT_BOTTOM]]:
// CHECK: apply [[BARRIER]]()
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK: apply [[BARRIER]]()
// CHECK-LABEL: } // end sil function 'lexical_end_at_end_4'
// CHECK-LABEL: end running test {{.*}} on lexical_end_at_end_4: canonicalize-ossa-lifetime
sil [ossa] @lexical_end_at_end_4 : $@convention(thin) (@owned C) -> () {
entry(%c1 : @owned $C):
specify_test "canonicalize-ossa-lifetime true false true @argument"
specify_test "canonicalize-ossa-lifetime true false true @argument %m %m2"
%takeC = function_ref @takeC : $@convention(thin) (@owned C) -> ()
%barrier = function_ref @barrier : $@convention(thin) () -> ()
cond_br undef, left, right_top
left:
%c2 = copy_value %c1 : $C
%m = move_value %c2 : $C
apply %takeC(%m) : $@convention(thin) (@owned C) -> ()
br exit
right_top:
cond_br undef, right_left, right_right
right_left:
%c2p = copy_value %c1 : $C
%m2 = move_value %c2p : $C
apply %takeC(%m2) : $@convention(thin) (@owned C) -> ()
br right_bottom
right_right:
apply %barrier() : $@convention(thin) () -> ()
br right_bottom
right_bottom:
apply %barrier() : $@convention(thin) () -> ()
br exit
exit:
apply %barrier() : $@convention(thin) () -> ()
destroy_value %c1 : $C
%retval = tuple ()
return %retval : $()
}
|