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

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 1 09:23:57 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1733
+
+    if (B->getZExtValue() == X - 1) {
+      Value *Cmp =
----------------
XChy wrote:
> 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?
A has the same type as Op0 and Op1


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