Add signExtend to ConstantRange, to complement zeroExtend and truncate.
authorNick Lewycky <nicholas@mxc.ca>
Sat, 7 Apr 2007 15:41:33 +0000 (15:41 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sat, 7 Apr 2007 15:41:33 +0000 (15:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35733 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ConstantRange.h
lib/Support/ConstantRange.cpp

index 05859b41116e1034a187248f6b7be553f1ac780a..020fb095ec02e2775d26f3914e98feaba224f443 100644 (file)
@@ -157,6 +157,12 @@ class ConstantRange {
   /// zero extended to BitWidth.
   ConstantRange zeroExtend(uint32_t BitWidth) const;
 
+  /// signExtend - Return a new range in the specified integer type, which must
+  /// be strictly larger than the current type.  The returned range will
+  /// correspond to the possible range of values if the source range had been
+  /// sign extended to BitWidth.
+  ConstantRange signExtend(uint32_t BitWidth) const;
+
   /// truncate - Return a new range in the specified integer type, which must be
   /// strictly smaller than the current type.  The returned range will
   /// correspond to the possible range of values if the source range had been
index dd3e44e4e92a0d7eea29b17a4ad8c72decc1b087..79a85b80d7ea3b1cc7f5184f570cc8058222e117 100644 (file)
@@ -346,6 +346,23 @@ ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
   return ConstantRange(L, U);
 }
 
+/// signExtend - Return a new range in the specified integer type, which must
+/// be strictly larger than the current type.  The returned range will
+/// correspond to the possible range of values as if the source range had been
+/// sign extended.
+ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
+  unsigned SrcTySize = getBitWidth();
+  assert(SrcTySize < DstTySize && "Not a value extension");
+  if (isFullSet()) {
+    return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
+                         APInt::getLowBitsSet(DstTySize, SrcTySize-1));
+  }
+
+  APInt L = Lower; L.sext(DstTySize);
+  APInt U = Upper; U.sext(DstTySize);
+  return ConstantRange(L, U);
+}
+
 /// truncate - Return a new range in the specified integer type, which must be
 /// strictly smaller than the current type.  The returned range will
 /// correspond to the possible range of values as if the source range had been