Skip to content

Commit fa4dd77

Browse files
committed
Update introduceTooComplexPhi
1 parent 4d5faa9 commit fa4dd77

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

llvm/lib/Transforms/Utils/Local.cpp

+16-24
Original file line numberDiff line numberDiff line change
@@ -1048,35 +1048,27 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ,
10481048
// Check whether removing BB will make the phis in its Succ have too
10491049
// many incoming entries. This function does not check whether BB is foldable
10501050
// 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) {
10561052
// If BB only has one predecessor, then removing it will not introduce more
10571053
// incoming edges for phis.
10581054
if (BB->hasNPredecessors(1))
10591055
return false;
10601056
int NumPreds = pred_size(BB);
1061-
auto *Succ = BB->getTerminator()->getSuccessor(0);
10621057
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;
10801072
}
10811073
return false;
10821074
}
@@ -1180,7 +1172,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
11801172
BBKillable ||
11811173
CanRedirectPredsOfEmptyBBToSucc(BB, Succ, BBPreds, SuccPreds, CommonPred);
11821174

1183-
if ((!BBKillable && !BBPhisMergeable) || introduceTooComplexPhi(BB))
1175+
if ((!BBKillable && !BBPhisMergeable) || introduceTooComplexPhi(BB, Succ))
11841176
return false;
11851177

11861178
// Check to see if merging these blocks/phis would cause conflicts for any of

0 commit comments

Comments
 (0)