[nfc][InstCombine]Find PHI incoming block by operand number (#93249)

This commit is contained in:
Mingming Liu 2024-05-24 14:19:02 -07:00 committed by GitHub
parent 8f21909c2f
commit 56c5ca8f66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5000,31 +5000,24 @@ bool InstCombinerImpl::run() {
BasicBlock *UserParent = nullptr; BasicBlock *UserParent = nullptr;
unsigned NumUsers = 0; unsigned NumUsers = 0;
for (auto *U : I->users()) { for (Use &U : I->uses()) {
if (U->isDroppable()) User *User = U.getUser();
if (User->isDroppable())
continue; continue;
if (NumUsers > MaxSinkNumUsers) if (NumUsers > MaxSinkNumUsers)
return std::nullopt; return std::nullopt;
Instruction *UserInst = cast<Instruction>(U); Instruction *UserInst = cast<Instruction>(User);
// Special handling for Phi nodes - get the block the use occurs in. // Special handling for Phi nodes - get the block the use occurs in.
if (PHINode *PN = dyn_cast<PHINode>(UserInst)) { BasicBlock *UserBB = UserInst->getParent();
for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) { if (PHINode *PN = dyn_cast<PHINode>(UserInst))
if (PN->getIncomingValue(i) == I) { UserBB = PN->getIncomingBlock(U);
// Bail out if we have uses in different blocks. We don't do any // Bail out if we have uses in different blocks. We don't do any
// sophisticated analysis (i.e finding NearestCommonDominator of // sophisticated analysis (i.e finding NearestCommonDominator of these
// these use blocks). // use blocks).
if (UserParent && UserParent != PN->getIncomingBlock(i)) if (UserParent && UserParent != UserBB)
return std::nullopt; return std::nullopt;
UserParent = PN->getIncomingBlock(i); UserParent = UserBB;
}
}
assert(UserParent && "expected to find user block!");
} else {
if (UserParent && UserParent != UserInst->getParent())
return std::nullopt;
UserParent = UserInst->getParent();
}
// Make sure these checks are done only once, naturally we do the checks // Make sure these checks are done only once, naturally we do the checks
// the first time we get the userparent, this will save compile time. // the first time we get the userparent, this will save compile time.