@@ -308,26 +308,29 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
308
308
// TODO: Is it safe to just eliminate the initial retain?
309
309
Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
310
310
311
- // If the source of a cast should be destroyed, emit a release.
311
+ // If we have an unconditional_checked_cast_addr, return early. We do not need
312
+ // to handle any conditional code.
312
313
if (isa<UnconditionalCheckedCastAddrInst>(Inst)) {
314
+ // Destroy the source value as unconditional_checked_cast_addr would.
313
315
Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
316
+ eraseInstAction (Inst);
317
+ return (newI) ? newI : AI;
314
318
}
315
319
316
- if (auto *CCABI = dyn_cast<CheckedCastAddrBranchInst>(Inst)) {
317
- switch (CCABI->getConsumptionKind ()) {
318
- case CastConsumptionKind::TakeAlways:
319
- Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
320
- break ;
321
- case CastConsumptionKind::TakeOnSuccess:
322
- // Insert a release in the success BB.
323
- Builder.setInsertionPoint (SuccessBB->begin ());
324
- Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
325
- break ;
326
- case CastConsumptionKind::BorrowAlways:
327
- llvm_unreachable (" checked_cast_addr_br never has BorrowAlways" );
328
- case CastConsumptionKind::CopyOnSuccess:
329
- break ;
330
- }
320
+ auto *CCABI = cast<CheckedCastAddrBranchInst>(Inst);
321
+ switch (CCABI->getConsumptionKind ()) {
322
+ case CastConsumptionKind::TakeAlways:
323
+ Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
324
+ break ;
325
+ case CastConsumptionKind::TakeOnSuccess:
326
+ // Insert a release in the success BB.
327
+ Builder.setInsertionPoint (SuccessBB->begin ());
328
+ Builder.createReleaseValue (Loc, srcOp, Builder.getDefaultAtomicity ());
329
+ break ;
330
+ case CastConsumptionKind::BorrowAlways:
331
+ llvm_unreachable (" checked_cast_addr_br never has BorrowAlways" );
332
+ case CastConsumptionKind::CopyOnSuccess:
333
+ break ;
331
334
}
332
335
333
336
// Results should be checked in case we process a conditional
0 commit comments