@@ -251,13 +251,12 @@ void CheckedCastBrJumpThreading::Edit::modifyCFGForFailurePreds(
251251 assert (!Cloner.wasCloned ());
252252 Cloner.cloneBlock ();
253253 SILBasicBlock *TargetFailureBB = Cloner.getNewBB ();
254- auto *TI = TargetFailureBB->getTerminator ();
255- SILBuilderWithScope Builder (TI);
256- // This BB copy branches to a FailureBB.
257- auto *CCBI = cast<CheckedCastBranchInst>(CCBBlock->getTerminator ());
258- Builder.createBranch (TI->getLoc (), CCBI->getFailureBB ());
259- TI->eraseFromParent ();
260- splitIfCriticalEdge (CCBBlock, CCBI->getFailureBB ());
254+ auto *clonedCCBI =
255+ cast<CheckedCastBranchInst>(TargetFailureBB->getTerminator ());
256+ SILBuilderWithScope Builder (clonedCCBI);
257+ // This BB copy branches to the FailureBB.
258+ Builder.createBranch (clonedCCBI->getLoc (), clonedCCBI->getFailureBB ());
259+ clonedCCBI->eraseFromParent ();
261260
262261 // Redirect all FailurePreds to the copy of BB.
263262 for (auto *Pred : FailurePreds) {
@@ -272,9 +271,9 @@ void CheckedCastBrJumpThreading::Edit::modifyCFGForFailurePreds(
272271// / a landing basic block for all FailurePreds.
273272void CheckedCastBrJumpThreading::Edit::modifyCFGForSuccessPreds (
274273 BasicBlockCloner &Cloner) {
275- auto *CCBI = cast<CheckedCastBranchInst>(CCBBlock->getTerminator ());
276274
277275 if (InvertSuccess) {
276+ auto *CCBI = cast<CheckedCastBranchInst>(CCBBlock->getTerminator ());
278277 SILBuilderWithScope (CCBI).createBranch (CCBI->getLoc (),
279278 CCBI->getFailureBB ());
280279 CCBI->eraseFromParent ();
@@ -287,13 +286,14 @@ void CheckedCastBrJumpThreading::Edit::modifyCFGForSuccessPreds(
287286 assert (!Cloner.wasCloned ());
288287 Cloner.cloneBlock ();
289288 SILBasicBlock *TargetSuccessBB = Cloner.getNewBB ();
290- auto *TI = TargetSuccessBB->getTerminator ();
291- SILBuilderWithScope Builder (TI);
289+ auto *clonedCCBI =
290+ cast<CheckedCastBranchInst>(TargetSuccessBB->getTerminator ());
291+ SILBuilderWithScope Builder (clonedCCBI);
292292 // This BB copy branches to SuccessBB.
293293 // Take argument value from the dominating BB.
294- Builder.createBranch (TI ->getLoc (), CCBI ->getSuccessBB (), {SuccessArg});
295- TI-> eraseFromParent ( );
296- splitIfCriticalEdge (CCBBlock, CCBI-> getSuccessBB () );
294+ Builder.createBranch (clonedCCBI ->getLoc (), clonedCCBI ->getSuccessBB (),
295+ {SuccessArg} );
296+ clonedCCBI-> eraseFromParent ( );
297297
298298 // Redirect all SuccessPreds to the copy of BB.
299299 for (auto *Pred : SuccessPreds) {
@@ -312,6 +312,7 @@ void CheckedCastBrJumpThreading::Edit::modifyCFGForSuccessPreds(
312312
313313 // Add an unconditional jump at the end of the block.
314314 // Take argument value from the dominating BB
315+ auto *CCBI = cast<CheckedCastBranchInst>(CCBBlock->getTerminator ());
315316 SILBuilderWithScope (CCBI).createBranch (CCBI->getLoc (), CCBI->getSuccessBB (),
316317 {SuccessArg});
317318 CCBI->eraseFromParent ();
0 commit comments