[PATCH] D126171: [InstCombine] fold icmp of zext bool based on limited range

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 22 12:54:12 PDT 2022


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:5647
+    Pred = I.getSwappedPredicate();
+  }
+
----------------
nikic wrote:
> Might make sense to use m_c_ICmp instead? Something along these lines:
> 
> ```
> if (match(I, m_c_ICmp(Pred, m_Value(X), m_OneUse(m_ZExt(m_Value(Y))))) &&
>     Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULT)
> ```
> 
> That would probably make it easier to extend this to the conjugate sext pattern: https://alive2.llvm.org/ce/z/2JTkdF
Ah, thanks - I knew there was a sibling, but I had not worked out the pattern. I'll add a TODO for that.

And yes, we can use the commutative matcher. I wasn't sure if we'd miss the transform if both operands are zexted, but it looks like other folds will convert that to something we can match more easily here. I'll add some more tests to confirm.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126171/new/

https://reviews.llvm.org/D126171



More information about the llvm-commits mailing list