[llvm] [CmpInstAnalysis] Decompose icmp eq (and x, C) C2 (PR #136367)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 23 00:54:16 PDT 2025


================
@@ -147,6 +150,19 @@ llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred,
 
     return std::nullopt;
   }
+  case ICmpInst::ICMP_EQ:
+  case ICmpInst::ICMP_NE: {
+    assert(DecomposeBitMask);
+    const APInt *AndC;
+    Value *AndVal;
+    if (match(LHS, m_And(m_Value(AndVal), m_APIntAllowPoison(AndC)))) {
+      Result = {AndVal /*X*/, Pred /*Pred*/, *AndC /*Mask*/, *OrigC /*C*/};
----------------
dtcxzyw wrote:

```suggestion
      LHS = AndVal;
      Result.Mask = *AndC;
      Result.C = C;
      Result.Pred = Pred;
```
In this way, we can catch the pattern `(trunc(X) & Mask) eq/ne C`.


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


More information about the llvm-commits mailing list