[PATCH] D88937: [KnownBits] Add a sextOrTrunc method
Quentin Colombet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 16:32:58 PDT 2020
qcolombet created this revision.
qcolombet added reviewers: fhahn, nikic, aqjune, spatel, RKSimon, efriedma, lebedev.ri.
Herald added a project: LLVM.
qcolombet requested review of this revision.
We already offer zextOrTrunc and it seems natural to offer the
same capability for sign extension.
This patch is a preparatory addition useful for future computeKnownBits
developments.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88937
Files:
llvm/include/llvm/Support/KnownBits.h
Index: llvm/include/llvm/Support/KnownBits.h
===================================================================
--- llvm/include/llvm/Support/KnownBits.h
+++ llvm/include/llvm/Support/KnownBits.h
@@ -166,6 +166,16 @@
return *this;
}
+ /// Return known bits for a sign extension or truncation of the value we're
+ /// tracking.
+ KnownBits sextOrTrunc(unsigned BitWidth) const {
+ if (BitWidth > getBitWidth())
+ return sext(BitWidth);
+ if (BitWidth < getBitWidth())
+ return trunc(BitWidth);
+ return *this;
+ }
+
/// Return a KnownBits with the extracted bits
/// [bitPosition,bitPosition+numBits).
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88937.296565.patch
Type: text/x-patch
Size: 714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201006/dcaf31da/attachment.bin>
More information about the llvm-commits
mailing list