[PATCH] D109620: [APInt] Add a concat method, use LLVM_UNLIKELY to help optimizer.

Chris Lattner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 13:57:35 PDT 2021


lattner added inline comments.


================
Comment at: llvm/include/llvm/ADT/APInt.h:351
     if (isSingleWord()) {
-      if (BitWidth == 0)
+      if (LLVM_UNLIKELY(BitWidth == 0))
         return false;
----------------
craig.topper wrote:
> This is may be too subtle, but we can avoid a branch here if we use.
> 
> U.VAL == WORDTYPE_MAX >> ((APINT_BITS_PER_WORD - BitWidth) & 0x3f);
> 
> That will alias 64 and 0 to both use WORD_TYPE for the compare. Since U.VAL should always be 0 for BitWidth == 0. The compare would always fail.
I like it, I'll pull this in.


================
Comment at: llvm/lib/Support/APInt.cpp:344
+  unsigned NewWidth = getBitWidth() + NewLSB.getBitWidth();
+  return (zext(NewWidth) << NewLSB.getBitWidth()) | NewLSB.zext(NewWidth);
+}
----------------
craig.topper wrote:
> I was wondering if insertBits would be better here, but the last resort code in that resorts to copying bit by bit. But it would avoid a second heap allocation for widening the LSB. So maybe worth improving insertBits.
I didn't spend much time worrying about this, but I'll look at improving this.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109620



More information about the llvm-commits mailing list