Skip to content

Commit 56c5ca8

Browse files
[nfc][InstCombine]Find PHI incoming block by operand number (#93249)
1 parent 8f21909 commit 56c5ca8

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,31 +5000,24 @@ bool InstCombinerImpl::run() {
50005000
BasicBlock *UserParent = nullptr;
50015001
unsigned NumUsers = 0;
50025002

5003-
for (auto *U : I->users()) {
5004-
if (U->isDroppable())
5003+
for (Use &U : I->uses()) {
5004+
User *User = U.getUser();
5005+
if (User->isDroppable())
50055006
continue;
50065007
if (NumUsers > MaxSinkNumUsers)
50075008
return std::nullopt;
50085009

5009-
Instruction *UserInst = cast<Instruction>(U);
5010+
Instruction *UserInst = cast<Instruction>(User);
50105011
// Special handling for Phi nodes - get the block the use occurs in.
5011-
if (PHINode *PN = dyn_cast<PHINode>(UserInst)) {
5012-
for (unsigned i = 0; i < PN->getNumIncomingValues(); i++) {
5013-
if (PN->getIncomingValue(i) == I) {
5014-
// Bail out if we have uses in different blocks. We don't do any
5015-
// sophisticated analysis (i.e finding NearestCommonDominator of
5016-
// these use blocks).
5017-
if (UserParent && UserParent != PN->getIncomingBlock(i))
5018-
return std::nullopt;
5019-
UserParent = PN->getIncomingBlock(i);
5020-
}
5021-
}
5022-
assert(UserParent && "expected to find user block!");
5023-
} else {
5024-
if (UserParent && UserParent != UserInst->getParent())
5025-
return std::nullopt;
5026-
UserParent = UserInst->getParent();
5027-
}
5012+
BasicBlock *UserBB = UserInst->getParent();
5013+
if (PHINode *PN = dyn_cast<PHINode>(UserInst))
5014+
UserBB = PN->getIncomingBlock(U);
5015+
// Bail out if we have uses in different blocks. We don't do any
5016+
// sophisticated analysis (i.e finding NearestCommonDominator of these
5017+
// use blocks).
5018+
if (UserParent && UserParent != UserBB)
5019+
return std::nullopt;
5020+
UserParent = UserBB;
50285021

50295022
// Make sure these checks are done only once, naturally we do the checks
50305023
// the first time we get the userparent, this will save compile time.

0 commit comments

Comments
 (0)