@@ -1048,35 +1048,27 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ,
1048
1048
// Check whether removing BB will make the phis in its Succ have too
1049
1049
// many incoming entries. This function does not check whether BB is foldable
1050
1050
// or not.
1051
- static bool introduceTooComplexPhi (BasicBlock *BB) {
1052
- // Check BB only has phi and an unconditional branch
1053
- BranchInst *Branch = dyn_cast<BranchInst>(BB->getFirstNonPHIOrDbg (true ));
1054
- assert (Branch && Branch->isUnconditional () && " BB is not an empty block" );
1055
-
1051
+ static bool introduceTooComplexPhi (BasicBlock *BB, BasicBlock *Succ) {
1056
1052
// If BB only has one predecessor, then removing it will not introduce more
1057
1053
// incoming edges for phis.
1058
1054
if (BB->hasNPredecessors (1 ))
1059
1055
return false ;
1060
1056
int NumPreds = pred_size (BB);
1061
- auto *Succ = BB->getTerminator ()->getSuccessor (0 );
1062
1057
for (auto &Phi : Succ->phis ()) {
1063
- int BlockIdx = Phi.getBasicBlockIndex (BB);
1064
- if (BlockIdx >= 0 ) {
1065
- // If the incoming value is a phi and the phi is defined in BB,
1066
- // then removing BB will not increase the total phi entries of the ir.
1067
- if (PHINode *IncomingPhi =
1068
- dyn_cast<PHINode>(Phi.getIncomingValue (BlockIdx)))
1069
- if (IncomingPhi->getParent () == BB)
1070
- continue ;
1071
- // Otherwise, we need to add (NumPreds - 1) entries to the phi node.
1072
- // If removing BB makes the phi have more than
1073
- // MaxPhiEntriesAfterRemovingEmptyBlock incoming values, then it will be
1074
- // considered as introducing too complex phi to the ir.
1075
- // The default threshold is 100.
1076
- if ((NumPreds - 1 ) + Phi.getNumIncomingValues () >
1077
- MaxPhiEntriesAfterRemovingEmptyBlock)
1078
- return true ;
1079
- }
1058
+ // If the incoming value is a phi and the phi is defined in BB,
1059
+ // then removing BB will not increase the total phi entries of the ir.
1060
+ if (PHINode *IncomingPhi =
1061
+ dyn_cast<PHINode>(Phi.getIncomingValueForBlock (BB)))
1062
+ if (IncomingPhi->getParent () == BB)
1063
+ continue ;
1064
+ // Otherwise, we need to add (NumPreds - 1) entries to the phi node.
1065
+ // If removing BB makes the phi have more than
1066
+ // MaxPhiEntriesAfterRemovingEmptyBlock incoming values, then it will be
1067
+ // considered as introducing too complex phi to the ir.
1068
+ // The default threshold is 100.
1069
+ if ((NumPreds - 1 ) + Phi.getNumIncomingValues () >
1070
+ MaxPhiEntriesAfterRemovingEmptyBlock)
1071
+ return true ;
1080
1072
}
1081
1073
return false ;
1082
1074
}
@@ -1180,7 +1172,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
1180
1172
BBKillable ||
1181
1173
CanRedirectPredsOfEmptyBBToSucc (BB, Succ, BBPreds, SuccPreds, CommonPred);
1182
1174
1183
- if ((!BBKillable && !BBPhisMergeable) || introduceTooComplexPhi (BB))
1175
+ if ((!BBKillable && !BBPhisMergeable) || introduceTooComplexPhi (BB, Succ ))
1184
1176
return false ;
1185
1177
1186
1178
// Check to see if merging these blocks/phis would cause conflicts for any of
0 commit comments