[PATCH] D154126: [InstCombine] Transform (A > 0) | (A < 0) -> zext (A != 0) fold

Hongyu Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 1 05:22:05 PDT 2023


XChy added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1733
+
+    if (B->getZExtValue() == X - 1) {
+      Value *Cmp =
----------------
nikic wrote:
> You can include this check directly in the match above using `m_SpecificInt(X - 1)`.
The type of `A` is determined **during** the match, but `X = A->getType()->getScalarSizeInBits()` must be passed to the `m_SpecificInt` **before** matching. Actually, X keep zero before the match.

Or do you mean something like:

```
auto MatchOrZExtICmp = [&](Value *Op0, Value *Op1) -> bool {
    const Value *X;
    return match(Op0, m_LShr(m_Value(A), m_Value(X))) &&
           match(X, m_SpecificInt(A->getType()->getScalarSizeInBits() - 1)) &&
           match(Op1, m_ZExt(m_ICmp(Pred, m_Specific(A), m_Zero())));
  };

```

 I'm not sure how to solve this problem. Could you help me with it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154126



More information about the llvm-commits mailing list