[llvm] 56c5ca8 - [nfc][InstCombine]Find PHI incoming block by operand number (#93249)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 24 14:19:05 PDT 2024
Author: Mingming Liu
Date: 2024-05-24T14:19:02-07:00
New Revision: 56c5ca8f6670a29dc726d65e24fde7dc047b04c3
URL: https://github.com/llvm/llvm-project/commit/56c5ca8f6670a29dc726d65e24fde7dc047b04c3
DIFF: https://github.com/llvm/llvm-project/commit/56c5ca8f6670a29dc726d65e24fde7dc047b04c3.diff
LOG: [nfc][InstCombine]Find PHI incoming block by operand number (#93249)
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6c25ff215c375..eb48157af009c 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -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
diff erent 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
diff erent 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.
More information about the llvm-commits
mailing list