@@ -233,12 +233,13 @@ bool SimplifyCFG::threadEdge(const ThreadInfo &ti) {
233
233
Builder.createBranch (SEI->getLoc (), ThreadedSuccessorBlock, {UED});
234
234
} else {
235
235
assert (SEI->getDefaultBB () == ThreadedSuccessorBlock);
236
- Builder.createBranch (SEI->getLoc (), ThreadedSuccessorBlock,
237
- SEI->getOperand ());
236
+ auto *OldBlockArg = ThreadedSuccessorBlock->getArgument (0 );
237
+ OldBlockArg->replaceAllUsesWith (SEI->getOperand ());
238
+ ThreadedSuccessorBlock->eraseArgument (0 );
239
+ Builder.createBranch (SEI->getLoc (), ThreadedSuccessorBlock);
238
240
}
239
241
} else {
240
- Builder.createBranch (SEI->getLoc (), ThreadedSuccessorBlock,
241
- ArrayRef<SILValue>());
242
+ Builder.createBranch (SEI->getLoc (), ThreadedSuccessorBlock);
242
243
}
243
244
SEI->eraseFromParent ();
244
245
}
@@ -502,11 +503,12 @@ bool SimplifyCFG::simplifyThreadedTerminators() {
502
503
if (auto *EI = dyn_cast<EnumInst>(SEI->getOperand ())) {
503
504
LLVM_DEBUG (llvm::dbgs () << " simplify threaded " << *SEI);
504
505
auto *LiveBlock = SEI->getCaseDestination (EI->getElement ());
505
- if (EI->hasOperand () && !LiveBlock->args_empty ()) {
506
- SILBuilderWithScope (SEI).createBranch (SEI->getLoc (), LiveBlock,
507
- EI->getOperand ());
508
- } else if (!LiveBlock->args_empty ()) {
509
- SILBuilderWithScope (SEI).createBranch (SEI->getLoc (), LiveBlock, {EI});
506
+ if (!LiveBlock->args_empty ()) {
507
+ auto *LiveBlockArg = LiveBlock->getArgument (0 );
508
+ auto NewValue = EI->hasOperand () ? EI->getOperand () : EI;
509
+ LiveBlockArg->replaceAllUsesWith (NewValue);
510
+ LiveBlock->eraseArgument (0 );
511
+ SILBuilderWithScope (SEI).createBranch (SEI->getLoc (), LiveBlock);
510
512
} else {
511
513
SILBuilderWithScope (SEI).createBranch (SEI->getLoc (), LiveBlock);
512
514
}
0 commit comments