[llvm] [PatternMatching] Add generic API for matching constants using custom conditions (PR #85676)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 22 19:52:38 PDT 2024


================
@@ -7144,33 +7144,37 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
 
   // Folding (X / Y) pred X => X swap(pred) 0 for constant Y other than 0 or 1
   {
-    const APInt *Divisor;
-    if (match(Op0, m_UDiv(m_Specific(Op1), m_APInt(Divisor))) &&
-        Divisor->ugt(1)) {
+    if (match(Op0,
+              m_UDiv(m_Specific(Op1), m_CheckedInt([](const APInt &Divisor) {
+                       return Divisor.ugt(1);
+                     })))) {
----------------
nikic wrote:

This is better than some alternatives, but this still makes the code significantly uglier exclusively for the sake of non-splat vectors. I'm not entirely convinced that this is a good tradeoff.

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


More information about the llvm-commits mailing list