diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2007-04-07 15:41:33 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2007-04-07 15:41:33 +0000 |
commit | e32157c6098ee7536315e9793eed98d21bf71fd0 (patch) | |
tree | 9845f84301447c9a35a9c84b73dbf01189fc2c43 /lib/Support/ConstantRange.cpp | |
parent | 8aaa40610cb327ff4568cf839a6b2d7c18aaa89b (diff) |
Add signExtend to ConstantRange, to complement zeroExtend and truncate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35733 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ConstantRange.cpp')
-rw-r--r-- | lib/Support/ConstantRange.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index dd3e44e4e9..79a85b80d7 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -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 |