diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-07-12 05:18:18 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-07-12 05:18:18 +0000 |
commit | a78be79bbf646a8d5812ab21a0e7cea124fe2cb2 (patch) | |
tree | 77e1223b81597152acf5973981606aad9bb38610 /lib/Support | |
parent | 634a4f51dd0568a85a46152fedcb9ca574bfeec8 (diff) | |
download | external_llvm-a78be79bbf646a8d5812ab21a0e7cea124fe2cb2.zip external_llvm-a78be79bbf646a8d5812ab21a0e7cea124fe2cb2.tar.gz external_llvm-a78be79bbf646a8d5812ab21a0e7cea124fe2cb2.tar.bz2 |
Implement udiv for ConstantRanges.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75413 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/ConstantRange.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 7fe1568..04a1b68 100644 --- a/lib/Support/ConstantRange.cpp +++ b/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... |