[llvm] [InstCombine] Replace an integer comparison of a `phi` node with multiple `ucmp`/`scmp` operands and a constant with `phi` of individual comparisons of original intrinsic's arguments (PR #107769)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 04:28:47 PDT 2024


================
@@ -1820,35 +1820,61 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) {
       continue;
     }
 
-    if (NonSimplifiedBB) return nullptr;  // More than one non-simplified value.
+    // If the only use of phi is comparing it with a constant then we can
+    // put this comparison in the incoming BB directly after a ucmp/scmp call
+    // because we know that it will simplify to a single icmp.
+    const APInt *Ignored;
+    if (isa<CmpIntrinsic>(InVal) && InVal->hasOneUse() &&
+        match(&I, m_c_ICmp(m_Specific(PN), m_APInt(Ignored)))) {
----------------
dtcxzyw wrote:

```suggestion
        match(&I, m_ICmp(m_Specific(PN), m_APInt(Ignored)))) {
```
We always place constants in RHS.


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


More information about the llvm-commits mailing list