@@ -2417,7 +2417,7 @@ static Value *ensureValueAvailableInSuccessor(Value *V, BasicBlock *BB,
24172417 // where OtherBB is the single other predecessor of BB's only successor.
24182418 PHINode *PHI = nullptr ;
24192419 BasicBlock *Succ = BB->getSingleSuccessor ();
2420-
2420+
24212421 for (auto I = Succ->begin (); isa<PHINode>(I); ++I)
24222422 if (cast<PHINode>(I)->getIncomingValueForBlock (BB) == V) {
24232423 PHI = cast<PHINode>(I);
@@ -2561,7 +2561,7 @@ static bool mergeConditionalStoreToAddress(BasicBlock *PTB, BasicBlock *PFB,
25612561
25622562 QStore->eraseFromParent ();
25632563 PStore->eraseFromParent ();
2564-
2564+
25652565 return true ;
25662566}
25672567
@@ -2593,7 +2593,7 @@ static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
25932593 // We model triangles as a type of diamond with a nullptr "true" block.
25942594 // Triangles are canonicalized so that the fallthrough edge is represented by
25952595 // a true condition, as in the diagram above.
2596- //
2596+ //
25972597 BasicBlock *PTB = PBI->getSuccessor (0 );
25982598 BasicBlock *PFB = PBI->getSuccessor (1 );
25992599 BasicBlock *QTB = QBI->getSuccessor (0 );
@@ -2652,7 +2652,7 @@ static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
26522652 if (StoreInst *SI = dyn_cast<StoreInst>(&I))
26532653 QStoreAddresses.insert (SI->getPointerOperand ());
26542654 }
2655-
2655+
26562656 set_intersect (PStoreAddresses, QStoreAddresses);
26572657 // set_intersect mutates PStoreAddresses in place. Rename it here to make it
26582658 // clear what it contains.
@@ -3381,7 +3381,12 @@ bool SimplifyCFGOpt::SimplifyCleanupReturn(CleanupReturnInst *RI) {
33813381 // This isn't an empty cleanup.
33823382 return false ;
33833383
3384- // Check that there are no other instructions except for debug intrinsics.
3384+ // We cannot kill the pad if it has multiple uses. This typically arises
3385+ // from unreachable basic blocks.
3386+ if (!CPInst->hasOneUse ())
3387+ return false ;
3388+
3389+ // Check that there are no other instructions except for benign intrinsics.
33853390 BasicBlock::iterator I = CPInst->getIterator (), E = RI->getIterator ();
33863391 while (++I != E)
33873392 if (!isa<DbgInfoIntrinsic>(I))
@@ -3818,17 +3823,17 @@ static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
38183823 }
38193824 }
38203825
3821- // If we can prove that the cases must cover all possible values, the
3822- // default destination becomes dead and we can remove it. If we know some
3826+ // If we can prove that the cases must cover all possible values, the
3827+ // default destination becomes dead and we can remove it. If we know some
38233828 // of the bits in the value, we can use that to more precisely compute the
38243829 // number of possible unique case values.
38253830 bool HasDefault =
38263831 !isa<UnreachableInst>(SI->getDefaultDest ()->getFirstNonPHIOrDbg ());
3827- const unsigned NumUnknownBits = Bits -
3832+ const unsigned NumUnknownBits = Bits -
38283833 (KnownZero.Or (KnownOne)).countPopulation ();
38293834 assert (NumUnknownBits <= Bits);
38303835 if (HasDefault && DeadCases.empty () &&
3831- NumUnknownBits < 64 /* avoid overflow */ &&
3836+ NumUnknownBits < 64 /* avoid overflow */ &&
38323837 SI->getNumCases () == (1ULL << NumUnknownBits)) {
38333838 DEBUG (dbgs () << " SimplifyCFG: switch default is dead.\n " );
38343839 BasicBlock *NewDefault = SplitBlockPredecessors (SI->getDefaultDest (),
@@ -4584,7 +4589,7 @@ static void reuseTableCompare(User *PhiUser, BasicBlock *PhiBlock,
45844589 assert ((CaseConst == TrueConst || CaseConst == FalseConst) &&
45854590 " Expect true or false as compare result." );
45864591 }
4587-
4592+
45884593 // Check if the branch instruction dominates the phi node. It's a simple
45894594 // dominance check, but sufficient for our needs.
45904595 // Although this check is invariant in the calling loops, it's better to do it
@@ -5149,7 +5154,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
51495154 if (PBI != BI && PBI->isConditional ())
51505155 if (mergeConditionalStores (PBI, BI))
51515156 return SimplifyCFG (BB, TTI, BonusInstThreshold, AC) | true ;
5152-
5157+
51535158 return false ;
51545159}
51555160
0 commit comments