[llvm] [InstCombine][NFC] Change the order of checks in SliceUpIllegalIntegerPHI for faster compile time. (PR #183726)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 10 08:24:22 PDT 2026


https://github.com/XinlongZHANG-Bob updated https://github.com/llvm/llvm-project/pull/183726

>From 560170b28a213cd444c283a7fe99c8076b7ba2dd Mon Sep 17 00:00:00 2001
From: XinlongZHANG-Bob <zhangxinlong.bob at bytedance.com>
Date: Fri, 27 Feb 2026 19:03:01 +0800
Subject: [PATCH] [InstCombine] Change the order of checks in
 SliceUpIllegalIntegerPHI for faster compile time.

SliceUpIllegalIntegerPHI searches for PHIs that have illegal type and
are only used by trunc or trunc(lshr) operations. It bails out if encounters
invoke or EH pad instructions.
It first checks whether it encounters invoke or EH pad, which is time consuming
as it checks every instruction. Then it checks whether it is used by trunc or
trunc(lshr). The former check is generally loose, while the latter one is stricter.
Switch the order of the checks will speed up compilation.

Signed-off-by: XinlongZHANG-Bob <zhangxinlong.bob at bytedance.com>
---
 .../Transforms/InstCombine/InstCombinePHI.cpp | 54 ++++++++++---------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 99fc7fcdb80e4..c4996e2583f2c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -1090,32 +1090,6 @@ Instruction *InstCombinerImpl::SliceUpIllegalIntegerPHI(PHINode &FirstPhi) {
   for (unsigned PHIId = 0; PHIId != PHIsToSlice.size(); ++PHIId) {
     PHINode *PN = PHIsToSlice[PHIId];
 
-    // Scan the input list of the PHI.  If any input is an invoke, and if the
-    // input is defined in the predecessor, then we won't be split the critical
-    // edge which is required to insert a truncate.  Because of this, we have to
-    // bail out.
-    for (auto Incoming : zip(PN->blocks(), PN->incoming_values())) {
-      BasicBlock *BB = std::get<0>(Incoming);
-      Value *V = std::get<1>(Incoming);
-      InvokeInst *II = dyn_cast<InvokeInst>(V);
-      if (!II)
-        continue;
-      if (II->getParent() != BB)
-        continue;
-
-      // If we have a phi, and if it's directly in the predecessor, then we have
-      // a critical edge where we need to put the truncate.  Since we can't
-      // split the edge in instcombine, we have to bail out.
-      return nullptr;
-    }
-
-    // If the incoming value is a PHI node before a catchswitch, we cannot
-    // extract the value within that BB because we cannot insert any non-PHI
-    // instructions in the BB.
-    for (auto *Pred : PN->blocks())
-      if (!Pred->hasInsertionPt())
-        return nullptr;
-
     for (User *U : PN->users()) {
       Instruction *UserI = cast<Instruction>(U);
 
@@ -1148,6 +1122,34 @@ Instruction *InstCombinerImpl::SliceUpIllegalIntegerPHI(PHINode &FirstPhi) {
     }
   }
 
+  for (const auto &PN : PHIsToSlice) {
+    // Scan the input list of the PHI.  If any input is an invoke, and if the
+    // input is defined in the predecessor, then we won't be split the critical
+    // edge which is required to insert a truncate.  Because of this, we have to
+    // bail out.
+    for (auto Incoming : zip(PN->blocks(), PN->incoming_values())) {
+      BasicBlock *BB = std::get<0>(Incoming);
+      Value *V = std::get<1>(Incoming);
+      InvokeInst *II = dyn_cast<InvokeInst>(V);
+      if (!II)
+        continue;
+      if (II->getParent() != BB)
+        continue;
+
+      // If we have a phi, and if it's directly in the predecessor, then we have
+      // a critical edge where we need to put the truncate.  Since we can't
+      // split the edge in instcombine, we have to bail out.
+      return nullptr;
+    }
+
+    // If the incoming value is a PHI node before a catchswitch, we cannot
+    // extract the value within that BB because we cannot insert any non-PHI
+    // instructions in the BB.
+    for (auto *Pred : PN->blocks())
+      if (!Pred->hasInsertionPt())
+        return nullptr;
+  }
+
   // If we have no users, they must be all self uses, just nuke the PHI.
   if (PHIUsers.empty())
     return replaceInstUsesWith(FirstPhi, PoisonValue::get(FirstPhi.getType()));



More information about the llvm-commits mailing list