File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
lib/SILOptimizer/SILCombiner Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -499,15 +499,24 @@ SILInstruction *SILCombiner::visitEndCOWMutationInst(EndCOWMutationInst *ECM) {
499
499
}
500
500
501
501
SILInstruction *
502
- SILCombiner::visitBridgeObjectToRefInst (BridgeObjectToRefInst *BORI) {
503
- if (BORI->getFunction ()->hasOwnership ())
504
- return nullptr ;
502
+ SILCombiner::visitBridgeObjectToRefInst (BridgeObjectToRefInst *bori) {
505
503
// Fold noop casts through Builtin.BridgeObject.
504
+ //
506
505
// (bridge_object_to_ref (unchecked-ref-cast x BridgeObject) y)
507
506
// -> (unchecked-ref-cast x y)
508
- if (auto URC = dyn_cast<UncheckedRefCastInst>(BORI->getOperand ()))
509
- return Builder.createUncheckedRefCast (BORI->getLoc (), URC->getOperand (),
510
- BORI->getType ());
507
+ if (auto *urc = dyn_cast<UncheckedRefCastInst>(bori->getOperand ())) {
508
+ if (SILValue (urc).getOwnershipKind () != OwnershipKind::Owned) {
509
+ return Builder.createUncheckedRefCast (
510
+ bori->getLoc (), urc->getOperand (), bori->getType ());
511
+ }
512
+ SingleBlockOwnedForwardingInstFolder folder (*this , bori);
513
+ if (folder.add (urc)) {
514
+ auto *newValue = Builder.createUncheckedRefCast (
515
+ bori->getLoc (), urc->getOperand (), bori->getType ());
516
+ return std::move (folder).optimizeWithReplacement (newValue);
517
+ }
518
+ }
519
+
511
520
return nullptr ;
512
521
}
513
522
You can’t perform that action at this time.
0 commit comments