[PATCH] D153148: [InstCombine] Fold `(-1 + A) & B` into `A ? 0 : B` where A is effectively a bool

Yingwei Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 17 06:17:04 PDT 2023


dtcxzyw added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2569
+  // Op0 & (-1 + zext(A)) --> A ? 0 : Op0
+  if (match(Op0, m_NSWAdd(m_ZExt(m_Value(A)), m_AllOnes())) &&
+      (A->getType()->isIntOrIntVectorTy(1) ||
----------------
nikic wrote:
> goldstein.w.n wrote:
> > The add doesn't need to be nsw
> Why does this need a zext?
It needs a zext to avoid creating redundant trunc (zext i1).



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153148



More information about the llvm-commits mailing list