[PATCH] D152675: [DAGCombine] Use `IsKnownNeverZero` to see if we need zero-check in is_pow2 setcc patern
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 11 23:29:29 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: RKSimon, pengfei.
Herald added subscribers: steven.zhang, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`ctpop(X) eq/ne 1` is checking if X is a non-zero power of 2. Power of
2 check including zero is `(X & (X-1)) eq/ne 0` and unfortunately
there is no good pattern for checking a power of 2 while excluding
zero. So, when lowering `ctpop(X) eq/ne 1`, explicitly check
`IsKnownNeverZero(X)` to maybe be able to optimize out the extra zero
check.
We need this explicitly as DAGCombiner does not re-analyze provable
setcc nodes, and the middle-end never finds it beneficially to broaden
`ctpop(X) eq/ne 1` -> `ctpop(X) ule/ugt 1` (power of 2 including
zero).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152675
Files:
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/ispow2.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152675.530398.patch
Type: text/x-patch
Size: 5757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230612/85813504/attachment.bin>
More information about the llvm-commits
mailing list