[PATCH] D136323: [ADT] Add APInt::isInvertOf

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 03:10:54 PDT 2022


nikic added a comment.

Do we get a benefit is we change only the `KnownBits::isConstant` implementation to do `Zero == ~One`?

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.)



================
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);
----------------
I think this will cause shift UB for zero-width APInts (yes, those are a thing now ...)


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