[llvm-commits] [llvm] r75413 - in /llvm/trunk: lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp
Nick Lewycky
nicholas at mxc.ca
Sat Jul 11 22:18:19 PDT 2009
Author: nicholas
Date: Sun Jul 12 00:18:18 2009
New Revision: 75413
URL: http://llvm.org/viewvc/llvm-project?rev=75413&view=rev
Log:
Implement udiv for ConstantRanges.
Modified:
llvm/trunk/lib/Support/ConstantRange.cpp
llvm/trunk/unittests/Support/ConstantRangeTest.cpp
Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=75413&r1=75412&r2=75413&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Sun Jul 12 00:18:18 2009
@@ -592,10 +592,32 @@
}
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...
Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=75413&r1=75412&r2=75413&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Sun Jul 12 00:18:18 2009
@@ -319,24 +319,20 @@
TEST_F(ConstantRangeTest, UDiv) {
EXPECT_EQ(Full.udiv(Full), Full);
EXPECT_EQ(Full.udiv(Empty), Empty);
- EXPECT_EQ(Full.udiv(One), Full);
- EXPECT_EQ(Full.udiv(Some), Full);
+ EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
+ APInt(16, 0xffff / 0xa + 1)));
+ EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
+ APInt(16, 0xffff / 0xa + 1)));
EXPECT_EQ(Full.udiv(Wrap), Full);
EXPECT_EQ(Empty.udiv(Empty), Empty);
EXPECT_EQ(Empty.udiv(One), Empty);
EXPECT_EQ(Empty.udiv(Some), Empty);
EXPECT_EQ(Empty.udiv(Wrap), Empty);
- // TODO: ConstantRange is currently over-conservative here.
- EXPECT_EQ(One.udiv(One), Full);
- // TODO: ConstantRange is currently over-conservative here.
- EXPECT_EQ(One.udiv(Some), Full);
- // TODO: ConstantRange is currently over-conservative here.
- EXPECT_EQ(One.udiv(Wrap), Full);
- // TODO: ConstantRange is currently over-conservative here.
- EXPECT_EQ(Some.udiv(Some), Full);
- // TODO: ConstantRange is currently over-conservative here.
- EXPECT_EQ(Some.udiv(Wrap), Full);
- // TODO: ConstantRange is currently over-conservative here.
+ EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
+ EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
+ EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
+ EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
+ EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_EQ(Wrap.udiv(Wrap), Full);
}
More information about the llvm-commits
mailing list