[llvm-commits] [llvm] r160294 - in /llvm/trunk: lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp
Duncan Sands
baldrick at free.fr
Tue Jul 17 00:25:53 PDT 2012
Hi Nuno,
> --- llvm/trunk/lib/Support/ConstantRange.cpp (original)
> +++ llvm/trunk/lib/Support/ConstantRange.cpp Mon Jul 16 13:08:12 2012
> @@ -143,16 +143,18 @@
> /// 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;
it's probably cheaper to just set the bit.
> +
> + if (isWrappedSet()) {
> + APInt Result = Upper + (APInt::getMaxValue(getBitWidth()) - Lower + 1);
This is the same as Upper - Lower.
Ciao, Duncan.
> + 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
>
> Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=160294&r1=160293&r2=160294&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
> +++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Mon Jul 16 13:08:12 2012
> @@ -114,11 +114,15 @@
> }
>
> TEST_F(ConstantRangeTest, GetSetSize) {
> - EXPECT_EQ(Full.getSetSize(), APInt(16, 0));
> - EXPECT_EQ(Empty.getSetSize(), APInt(16, 0));
> - EXPECT_EQ(One.getSetSize(), APInt(16, 1));
> - EXPECT_EQ(Some.getSetSize(), APInt(16, 0xaa0));
> - EXPECT_EQ(Wrap.getSetSize(), APInt(16, 0x10000 - 0xaa0));
> + EXPECT_EQ(Full.getSetSize(), APInt(17, 65536));
> + EXPECT_EQ(Empty.getSetSize(), APInt(17, 0));
> + EXPECT_EQ(One.getSetSize(), APInt(17, 1));
> + EXPECT_EQ(Some.getSetSize(), APInt(17, 0xaa0));
> +
> + ConstantRange Wrap(APInt(4, 7), APInt(4, 3));
> + ConstantRange Wrap2(APInt(4, 8), APInt(4, 7));
> + EXPECT_EQ(Wrap.getSetSize(), APInt(5, 12));
> + EXPECT_EQ(Wrap2.getSetSize(), APInt(5, 15));
> }
>
> TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list