summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/ConstantRange.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-07-12 05:18:18 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-07-12 05:18:18 +0000
commitf1b8cb37602e7228a37f6eda539e657b460dc3b0 (patch)
tree86bd6babbb8e5b204869936c320f212dad5e9e51 /llvm/lib/Support/ConstantRange.cpp
parent5b76fc03ae73a5d407b5af4714ac6aa2af9fbb9a (diff)
downloadbcm5719-llvm-f1b8cb37602e7228a37f6eda539e657b460dc3b0.tar.gz
bcm5719-llvm-f1b8cb37602e7228a37f6eda539e657b460dc3b0.zip
Implement udiv for ConstantRanges.
llvm-svn: 75413
Diffstat (limited to 'llvm/lib/Support/ConstantRange.cpp')
-rw-r--r--llvm/lib/Support/ConstantRange.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp
index 7fe156835db..04a1b68e072 100644
--- a/llvm/lib/Support/ConstantRange.cpp
+++ b/llvm/lib/Support/ConstantRange.cpp
@@ -592,10 +592,32 @@ ConstantRange::umax(const ConstantRange &Other) const {
}
ConstantRange
-ConstantRange::udiv(const ConstantRange &Other) const {
- // TODO: Implement udiv.
- return ConstantRange(getBitWidth(),
- !(isEmptySet() || Other.isEmptySet()));
+ConstantRange::udiv(const ConstantRange &RHS) const {
+ if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax() == 0)
+ return ConstantRange(getBitWidth(), /*isFullSet=*/false);
+ if (RHS.isFullSet())
+ return ConstantRange(getBitWidth(), /*isFullSet=*/true);
+
+ APInt Lower = getUnsignedMin().udiv(RHS.getUnsignedMax());
+
+ APInt RHS_umin = RHS.getUnsignedMin();
+ if (RHS_umin == 0) {
+ // We want the lowest value in RHS excluding zero. Usually that would be 1
+ // except for a range in the form of [X, 1) in which case it would be X.
+ if (RHS.getUpper() == 1)
+ RHS_umin = RHS.getLower();
+ else
+ RHS_umin = APInt(getBitWidth(), 1);
+ }
+
+ APInt Upper = getUnsignedMax().udiv(RHS_umin) + 1;
+
+ // If the LHS is Full and the RHS is a wrapped interval containing 1 then
+ // this could occur.
+ if (Lower == Upper)
+ return ConstantRange(getBitWidth(), /*isFullSet=*/true);
+
+ return ConstantRange(Lower, Upper);
}
/// print - Print out the bounds to a stream...
OpenPOWER on IntegriCloud