@@ -1346,6 +1346,19 @@ static void salvageDebugInfoFromEmptyBlock(const TargetInstrInfo *TII,
13461346 copyDebugInfoToPredecessor (TII, MBB, *PredBB);
13471347}
13481348
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+
13491362bool BranchFolder::OptimizeBlock (MachineBasicBlock *MBB) {
13501363 bool MadeChange = false ;
13511364 MachineFunction &MF = *MBB->getParent ();
@@ -1389,6 +1402,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
13891402 // TODO: Is it ever worth rewriting predecessors which don't already
13901403 // jump to a landing pad, and so can safely jump to the fallthrough?
13911404 } else if (MBB->isSuccessor (&*FallThrough)) {
1405+ if (!TII->isMBBSafeToBranchFolding (*MBB) &&
1406+ !areAllPredsAnalyzable (TII, MBB))
1407+ return MadeChange;
13921408 // Rewrite all predecessors of the old block to go to the fallthrough
13931409 // instead.
13941410 while (!MBB->pred_empty ()) {
0 commit comments