[llvm] [InstCombine] Simplify phi using KnownBits of condition (PR #134712)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 7 23:03:01 PDT 2025


================
@@ -1625,6 +1625,25 @@ Instruction *InstCombinerImpl::visitPHINode(PHINode &PN) {
     return replaceInstUsesWith(PN, &IdenticalPN);
   }
 
+  if (PN.getType()->isIntegerTy()) {
+    bool MadeChange = false;
+    SimplifyQuery Q = SQ.getWithInstruction(&PN);
+    for (unsigned I = 0, E = PN.getNumIncomingValues(); I != E; ++I) {
+      Value *V = PN.getIncomingValue(I);
+      if (isa<ConstantInt>(V))
+        continue;
+
----------------
andjo403 wrote:

> Compile-time overhead: +~0.2%

maybe having a check like this can help the compile time regression:

```suggestion
      if (auto *BI =
              dyn_cast<BranchInst>(PN.getIncomingBlock(I)->getTerminator()))
        if (BI->isUnconditional())
          continue;

```
think that it only is for this that this simplification is needed

https://github.com/llvm/llvm-project/pull/134712


More information about the llvm-commits mailing list