[PATCH] D111113: [APInt] Make insertBits and concat work with zero width APInts.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 6 04:20:05 PDT 2021


foad added inline comments.


================
Comment at: llvm/lib/Support/APInt.cpp:348
   unsigned NewWidth = getBitWidth() + NewLSB.getBitWidth();
-  APInt Result = NewLSB.zext(NewWidth);
+  APInt Result = NewLSB.zextOrSelf(NewWidth);
   Result.insertBits(*this, NewLSB.getBitWidth());
----------------
lattner wrote:
> foad wrote:
> > Just a pet peeve, I would much prefer that methods like zext and trunc allow the degenerate cases where you're extending or truncating to the same width. I think having separate "OrSelf" versions just adds clutter for no real benefit.
> I agree completely,  would you like to allow this and deprecate the "OrSelf" versions?
I have four patches for this:
1. Allow zext/sext/trunc to the same width
2. Change all users of xxxOrSelf to use the standard functions. (This isn't completely trivial because some users rely on the strange undocumented behaviour of the OrSelf functions, where they allow extending to a **smaller** width or truncating to a **larger** width, and treat it as a no-op.)
3. Deprecate the OrSelf functions
4. Remove the OrSelf functions
Is splitting it into four excessive?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111113



More information about the llvm-commits mailing list