[llvm] [nfc][InstCombine]Find PHI incoming block by operand number (PR #93249)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 15:15:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Mingming Liu (minglotus-6)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/93249.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+15-14)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6c25ff215c375..b0361db1708f9 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -5000,26 +5000,27 @@ 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!");
+ unsigned Num =
+ PHINode::getIncomingValueNumForOperand(U.getOperandNo());
+ assert(PN->getIncomingValue(Num) == I && "Expect from def-use chain");
+
+ // Bail out if we have uses in different blocks. We don't do any
+ // sophisticated analysis (i.e finding NearestCommonDominator of
+ // these use blocks).
+ BasicBlock* IncomingBlock = PN->getIncomingBlock(Num);
+ if (UserParent && UserParent != IncomingBlock)
+ return std::nullopt;
+ UserParent = PN->getIncomingBlock(Num);
} else {
if (UserParent && UserParent != UserInst->getParent())
return std::nullopt;
``````````
</details>
https://github.com/llvm/llvm-project/pull/93249
More information about the llvm-commits
mailing list