aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/ConstantRange.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-16 18:08:12 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-16 18:08:12 +0000
commit367308f798338e162b4ab76efa785caa847487c0 (patch)
tree5511db0ab92077212598651dd7622c923bed1d59 /lib/Support/ConstantRange.cpp
parent3591955bce8dd3fe638a913f23bf479670dbff4d (diff)
downloadexternal_llvm-367308f798338e162b4ab76efa785caa847487c0.zip
external_llvm-367308f798338e162b4ab76efa785caa847487c0.tar.gz
external_llvm-367308f798338e162b4ab76efa785caa847487c0.tar.bz2
make ConstantRange::getSetSize() properly compute the size of wrapped and full sets.
Make it always return APInts with the same bitwidth for the same ConstantRange bitwidth to simply clients git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ConstantRange.cpp')
-rw-r--r--lib/Support/ConstantRange.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 91d086b..b83dccc 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -143,16 +143,18 @@ bool ConstantRange::isSignWrappedSet() const {
/// getSetSize - Return the number of elements in this set.
///
APInt ConstantRange::getSetSize() const {
- if (isEmptySet())
- return APInt(getBitWidth(), 0);
- if (getBitWidth() == 1) {
- if (Lower != Upper) // One of T or F in the set...
- return APInt(2, 1);
- return APInt(2, 2); // Must be full set...
+ if (isEmptySet())
+ return APInt(getBitWidth()+1, 0);
+
+ if (isFullSet())
+ return APInt::getMaxValue(getBitWidth()).zext(getBitWidth()+1) + 1;
+
+ if (isWrappedSet()) {
+ APInt Result = Upper + (APInt::getMaxValue(getBitWidth()) - Lower + 1);
+ return Result.zext(getBitWidth()+1);
}
- // Simply subtract the bounds...
- return Upper - Lower;
+ return (Upper - Lower).zext(getBitWidth()+1);
}
/// getUnsignedMax - Return the largest unsigned value contained in the