[llvm] [InstCombine] Simplify select if it combinated and/or/xor (PR #73362)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 10:44:17 PDT 2024


goldsteinn wrote:

> @goldsteinn thanks for review. I wish I could take TODOs.

You can, I think the way to do this is actually to handle this case in `computeKnownBitsFromCmp`.

We currently have:
```
 else if (match(LHS, m_And(m_V, m_APInt(Mask))) &&
               match(RHS, m_APInt(C))) {
      // For one bits in Mask, we can propagate bits from C to V.
      Known.Zero |= ~*C & *Mask;
      Known.One |= *C & *Mask;
      // assume(V | Mask = C)
    }
```

But we could (and should) also have:
```
 else if (match(LHS, m_c_And(m_V, m_Value()) &&
               match(RHS, m_APInt(C))) {
      Known.One |= *C;
   }
```

Likewise for the `or` case:

```
 else if (match(LHS, m_c_Or(m_V, m_Value()) &&
               match(RHS, m_APInt(C))) {
      Known.Zero |= ~*C;
   }
```

The only case that requires special logic is `xor` where we can't actually deduce any bits, but we
can deduce non-common bits.

That case I think you could handle here in a future patch.

Let me know if you are going to pursue a patch in `computeKnownBitsFromCmp`.

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


More information about the llvm-commits mailing list