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

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 15:08:19 PDT 2024


https://github.com/minglotus-6 created https://github.com/llvm/llvm-project/pull/93249

None

>From 493cdcaa98ac7ccbaca6c1ec892de3f82dbdb7d3 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Thu, 23 May 2024 15:07:33 -0700
Subject: [PATCH] [nfc][InstCombine]Find PHI incoming block by operand number

---
 .../InstCombine/InstructionCombining.cpp      | 28 +++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6c25ff215c375..974edc8d5a8fc 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -5000,26 +5000,26 @@ 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).
+          if (UserParent && UserParent != PN->getIncomingBlock(Num))
+            return std::nullopt;
+          UserParent = PN->getIncomingBlock(Num);
         } else {
           if (UserParent && UserParent != UserInst->getParent())
             return std::nullopt;



More information about the llvm-commits mailing list