Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5000,31 +5000,24 @@ bool InstCombinerImpl::run() {
BasicBlock *UserParent = nullptr;
unsigned NumUsers = 0;

for (auto *U : I->users()) {
if (U->isDroppable())
for (Use &U : I->uses()) {
User *User = U.getUser();
if (User->isDroppable())
continue;
if (NumUsers > MaxSinkNumUsers)
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.
if (PHINode *PN = dyn_cast<PHINode>(UserInst)) {
for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) {
if (PN->getIncomingValue(i) == I) {
// Bail out if we have uses in different blocks. We don't do any
// sophisticated analysis (i.e finding NearestCommonDominator of
// these use blocks).
if (UserParent && UserParent != PN->getIncomingBlock(i))
return std::nullopt;
UserParent = PN->getIncomingBlock(i);
}
}
assert(UserParent && "expected to find user block!");
} else {
if (UserParent && UserParent != UserInst->getParent())
return std::nullopt;
UserParent = UserInst->getParent();
}
BasicBlock *UserBB = UserInst->getParent();
if (PHINode *PN = dyn_cast<PHINode>(UserInst))
UserBB = PN->getIncomingBlock(U);
// Bail out if we have uses in different blocks. We don't do any
// sophisticated analysis (i.e finding NearestCommonDominator of these
// use blocks).
if (UserParent && UserParent != UserBB)
return std::nullopt;
UserParent = UserBB;

// 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.
Expand Down
Loading