[PATCH] D152677: [InstCombine] If there is a known-bit transform is_pow2 check to just check for any other bits

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 12 10:27:30 PDT 2023


goldstein.w.n marked an inline comment as done.
goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6774
+    // Power of 2 test:
+    //    isPow2OrZero : ctpop(X) u< 2
+    //    isPow2       : ctpop(X) == 1
----------------
nikic wrote:
> Do you think it would make sense to canonicalize `ctpop(X) < 2` to `ctpop(X) == 1` if `isKnownNonZero(X)`? Or does this run into the issue that `ctpop(X) < 2` is actually the cheaper check once expanded, and we might not recover the non-zero fact at that point anymore?
`ctpop(X) < 2` is cheaper for the backend and indeed isknownnonzero is often 'lost' by the backend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152677



More information about the llvm-commits mailing list