aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/ConstantRange.h6
-rw-r--r--lib/Support/ConstantRange.cpp17
2 files changed, 23 insertions, 0 deletions
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index 05859b4111..020fb095ec 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -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
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