[PATCH] D136323: [ADT] Add APInt::isInvertOf
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 24 02:40:49 PDT 2022
serge-sans-paille added a comment.
In D136323#3873957 <https://reviews.llvm.org/D136323#3873957>, @nikic wrote:
> Do we get a benefit is we change only the `KnownBits::isConstant` implementation to do `Zero == ~One`?
I've checked and the answer is no (at least as long as `popcnt` is available. `(One | Zero).countPopulation() == getBitWidth()` also is an alternative but it's not significantly faster.
> In terms of readability, I find `X == ~Y` clearer than `X.isInvertOf(Y)`, so I personally wouldn't do this without some noticeable impact. (Though I'm not particularly opposed either.)
ok, let's forget about it!
================
Comment at: llvm/include/llvm/ADT/APInt.h:931
+ if (isSingleWord()) {
+ uint64_t Mask = (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth));
+ return U.VAL == (~RHS.U.VAL & Mask);
----------------
nikic wrote:
> I think this will cause shift UB for zero-width APInts (yes, those are a thing now ...)
indeed
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136323/new/
https://reviews.llvm.org/D136323
More information about the llvm-commits
mailing list