@@ -2417,7 +2417,7 @@ static Value *ensureValueAvailableInSuccessor(Value *V, BasicBlock *BB,
2417
2417
// where OtherBB is the single other predecessor of BB's only successor.
2418
2418
PHINode *PHI = nullptr ;
2419
2419
BasicBlock *Succ = BB->getSingleSuccessor ();
2420
-
2420
+
2421
2421
for (auto I = Succ->begin (); isa<PHINode>(I); ++I)
2422
2422
if (cast<PHINode>(I)->getIncomingValueForBlock (BB) == V) {
2423
2423
PHI = cast<PHINode>(I);
@@ -2561,7 +2561,7 @@ static bool mergeConditionalStoreToAddress(BasicBlock *PTB, BasicBlock *PFB,
2561
2561
2562
2562
QStore->eraseFromParent ();
2563
2563
PStore->eraseFromParent ();
2564
-
2564
+
2565
2565
return true ;
2566
2566
}
2567
2567
@@ -2593,7 +2593,7 @@ static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
2593
2593
// We model triangles as a type of diamond with a nullptr "true" block.
2594
2594
// Triangles are canonicalized so that the fallthrough edge is represented by
2595
2595
// a true condition, as in the diagram above.
2596
- //
2596
+ //
2597
2597
BasicBlock *PTB = PBI->getSuccessor (0 );
2598
2598
BasicBlock *PFB = PBI->getSuccessor (1 );
2599
2599
BasicBlock *QTB = QBI->getSuccessor (0 );
@@ -2652,7 +2652,7 @@ static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
2652
2652
if (StoreInst *SI = dyn_cast<StoreInst>(&I))
2653
2653
QStoreAddresses.insert (SI->getPointerOperand ());
2654
2654
}
2655
-
2655
+
2656
2656
set_intersect (PStoreAddresses, QStoreAddresses);
2657
2657
// set_intersect mutates PStoreAddresses in place. Rename it here to make it
2658
2658
// clear what it contains.
@@ -3381,7 +3381,12 @@ bool SimplifyCFGOpt::SimplifyCleanupReturn(CleanupReturnInst *RI) {
3381
3381
// This isn't an empty cleanup.
3382
3382
return false ;
3383
3383
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.
3385
3390
BasicBlock::iterator I = CPInst->getIterator (), E = RI->getIterator ();
3386
3391
while (++I != E)
3387
3392
if (!isa<DbgInfoIntrinsic>(I))
@@ -3818,17 +3823,17 @@ static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
3818
3823
}
3819
3824
}
3820
3825
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
3823
3828
// of the bits in the value, we can use that to more precisely compute the
3824
3829
// number of possible unique case values.
3825
3830
bool HasDefault =
3826
3831
!isa<UnreachableInst>(SI->getDefaultDest ()->getFirstNonPHIOrDbg ());
3827
- const unsigned NumUnknownBits = Bits -
3832
+ const unsigned NumUnknownBits = Bits -
3828
3833
(KnownZero.Or (KnownOne)).countPopulation ();
3829
3834
assert (NumUnknownBits <= Bits);
3830
3835
if (HasDefault && DeadCases.empty () &&
3831
- NumUnknownBits < 64 /* avoid overflow */ &&
3836
+ NumUnknownBits < 64 /* avoid overflow */ &&
3832
3837
SI->getNumCases () == (1ULL << NumUnknownBits)) {
3833
3838
DEBUG (dbgs () << " SimplifyCFG: switch default is dead.\n " );
3834
3839
BasicBlock *NewDefault = SplitBlockPredecessors (SI->getDefaultDest (),
@@ -4584,7 +4589,7 @@ static void reuseTableCompare(User *PhiUser, BasicBlock *PhiBlock,
4584
4589
assert ((CaseConst == TrueConst || CaseConst == FalseConst) &&
4585
4590
" Expect true or false as compare result." );
4586
4591
}
4587
-
4592
+
4588
4593
// Check if the branch instruction dominates the phi node. It's a simple
4589
4594
// dominance check, but sufficient for our needs.
4590
4595
// 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) {
5149
5154
if (PBI != BI && PBI->isConditional ())
5150
5155
if (mergeConditionalStores (PBI, BI))
5151
5156
return SimplifyCFG (BB, TTI, BonusInstThreshold, AC) | true ;
5152
-
5157
+
5153
5158
return false ;
5154
5159
}
5155
5160
0 commit comments