[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)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 09:46:24 PDT 2024


================
@@ -1820,6 +1821,16 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) {
       continue;
     }
 
+    // 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.
+    if (isa<CmpIntrinsic>(InVal) &&
+        match(&I, m_c_ICmp(m_Specific(PN), m_Constant()))) {
----------------
nikic wrote:

This should also check that the CmpIntrinsic is one-use and m_Constant() should be m_APInt(), because we only fold in that case.

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


More information about the llvm-commits mailing list