@@ -1346,6 +1346,19 @@ static void salvageDebugInfoFromEmptyBlock(const TargetInstrInfo *TII,
1346
1346
copyDebugInfoToPredecessor (TII, MBB, *PredBB);
1347
1347
}
1348
1348
1349
+ static bool areAllPredsAnalyzable (const llvm::TargetInstrInfo *TII,
1350
+ MachineBasicBlock *MBB) {
1351
+ for (auto itr = MBB->pred_begin (); itr != MBB->pred_end (); ++itr) {
1352
+ MachineBasicBlock *CurTBB = nullptr , *CurFBB = nullptr ;
1353
+ SmallVector<MachineOperand, 4 > CurCond;
1354
+ bool CantAnalyzable = TII->analyzeBranch (**itr, CurTBB, CurFBB, CurCond,
1355
+ /* AllowModify*/ false );
1356
+ if (CantAnalyzable)
1357
+ return false ;
1358
+ }
1359
+ return true ;
1360
+ }
1361
+
1349
1362
bool BranchFolder::OptimizeBlock (MachineBasicBlock *MBB) {
1350
1363
bool MadeChange = false ;
1351
1364
MachineFunction &MF = *MBB->getParent ();
@@ -1389,6 +1402,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
1389
1402
// TODO: Is it ever worth rewriting predecessors which don't already
1390
1403
// jump to a landing pad, and so can safely jump to the fallthrough?
1391
1404
} else if (MBB->isSuccessor (&*FallThrough)) {
1405
+ if (!TII->isMBBSafeToBranchFolding (*MBB) &&
1406
+ !areAllPredsAnalyzable (TII, MBB))
1407
+ return MadeChange;
1392
1408
// Rewrite all predecessors of the old block to go to the fallthrough
1393
1409
// instead.
1394
1410
while (!MBB->pred_empty ()) {
0 commit comments