[llvm] [InstCombine] Missed optimization: Fold (sext(a) & sext(c1)) == c2 to (a & c1) == c2 (PR #112646)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 07:49:13 PDT 2024


================
@@ -7687,6 +7688,29 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
   if (Instruction *Res = foldReductionIdiom(I, Builder, DL))
     return Res;
 
+  {
+    Value *A, *B;
+    const APInt *C;
+    ICmpInst::Predicate PredEq = ICmpInst::ICMP_EQ;
+    if (I.getPredicate() == PredEq) {
+      if (match(Op0, m_And(m_Value(A), m_APInt(C))) && match(Op1, m_One())) {
----------------
goldsteinn wrote:

Just matching `m_And(m_SExtLike(m_Value(A)...)` seems simpler.

Note `m_SExtLike` just matches `sext` or a `zext` that is provably equivilent to a `sext` due to the `nneg` IR flag.

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


More information about the llvm-commits mailing list