@@ -1248,21 +1248,8 @@ bool SimplifyCFG::simplifyBranchBlock(BranchInst *BI) {
1248
1248
LLVM_DEBUG (llvm::dbgs () << " merge bb" << BB->getDebugID () << " with bb"
1249
1249
<< DestBB->getDebugID () << ' \n ' );
1250
1250
1251
- // If there are any BB arguments in the destination, replace them with the
1252
- // branch operands, since they must dominate the dest block.
1253
1251
for (unsigned i = 0 , e = BI->getArgs ().size (); i != e; ++i) {
1254
- if (DestBB->getArgument (i) != BI->getArg (i)) {
1255
- SILValue Val = BI->getArg (i);
1256
- DestBB->getArgument (i)->replaceAllUsesWith (Val);
1257
- if (!isVeryLargeFunction) {
1258
- if (auto *I = dyn_cast<SingleValueInstruction>(Val)) {
1259
- // Replacing operands may trigger constant folding which then could
1260
- // trigger other simplify-CFG optimizations.
1261
- ConstFolder.addToWorklist (I);
1262
- ConstFolder.processWorkList ();
1263
- }
1264
- }
1265
- } else {
1252
+ if (DestBB->getArgument (i) == BI->getArg (i)) {
1266
1253
// We must be processing an unreachable part of the cfg with a cycle.
1267
1254
// bb1(arg1): // preds: bb3
1268
1255
// br bb2
@@ -1273,6 +1260,23 @@ bool SimplifyCFG::simplifyBranchBlock(BranchInst *BI) {
1273
1260
// bb3: // preds: bb2
1274
1261
// br bb1(arg1)
1275
1262
assert (!isReachable (BB) && " Should only occur in unreachable block" );
1263
+ return Simplified;
1264
+ }
1265
+ }
1266
+
1267
+ // If there are any BB arguments in the destination, replace them with the
1268
+ // branch operands, since they must dominate the dest block.
1269
+ for (unsigned i = 0 , e = BI->getArgs ().size (); i != e; ++i) {
1270
+ assert (DestBB->getArgument (i) != BI->getArg (i));
1271
+ SILValue Val = BI->getArg (i);
1272
+ DestBB->getArgument (i)->replaceAllUsesWith (Val);
1273
+ if (!isVeryLargeFunction) {
1274
+ if (auto *I = dyn_cast<SingleValueInstruction>(Val)) {
1275
+ // Replacing operands may trigger constant folding which then could
1276
+ // trigger other simplify-CFG optimizations.
1277
+ ConstFolder.addToWorklist (I);
1278
+ ConstFolder.processWorkList ();
1279
+ }
1276
1280
}
1277
1281
}
1278
1282
0 commit comments