diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-03-03 18:31:16 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-03-03 18:31:16 +0000 |
commit | f3867e64a82570990461e377c44887a310389ce8 (patch) | |
tree | 724d61721b77236c6c964a53e17dc24b5a45dcd2 /llvm/unittests/IR/ConstantRangeTest.cpp | |
parent | 3035719c86812d83e0bf9320ba5153a219f4635c (diff) | |
download | bcm5719-llvm-f3867e64a82570990461e377c44887a310389ce8.tar.gz bcm5719-llvm-f3867e64a82570990461e377c44887a310389ce8.zip |
[ConstantRange] Generalize makeGuaranteedNoWrapRegion to work on ranges
This will be used in a later patch to ScalarEvolution. Right now only
the unit tests exercise the newly added code.
llvm-svn: 262637
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 35b1db3ed42..a06483dfe49 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -657,6 +657,63 @@ TEST(ConstantRange, MakeOverflowingRegion) { EXPECT_FALSE(Overflow); } } + + auto NSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, ConstantRange(32, /* isFullSet = */ true), + OBO::NoSignedWrap); + EXPECT_TRUE(NSWForAllValues.isSingleElement() && + NSWForAllValues.getSingleElement()->isMinValue()); + + auto NUWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, ConstantRange(32, /* isFullSet = */ true), + OBO::NoUnsignedWrap); + EXPECT_TRUE(NUWForAllValues.isSingleElement() && + NSWForAllValues.getSingleElement()->isMinValue()); + + auto NUWAndNSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, ConstantRange(32, /* isFullSet = */ true), + OBO::NoUnsignedWrap | OBO::NoSignedWrap); + EXPECT_TRUE(NUWAndNSWForAllValues.isSingleElement() && + NSWForAllValues.getSingleElement()->isMinValue()); + + ConstantRange OneToFive(APInt(32, 1), APInt(32, 6)); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, OneToFive, OBO::NoSignedWrap), + ConstantRange(APInt::getSignedMinValue(32), + APInt::getSignedMaxValue(32) - 4)); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, OneToFive, OBO::NoUnsignedWrap), + ConstantRange(APInt::getMinValue(32), APInt::getMinValue(32) - 5)); + EXPECT_EQ( + ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, OneToFive, OBO::NoUnsignedWrap | OBO::NoSignedWrap), + ConstantRange(APInt::getMinValue(32), APInt::getSignedMaxValue(32) - 4)); + + ConstantRange MinusFiveToMinusTwo(APInt(32, -5), APInt(32, -1)); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusFiveToMinusTwo, OBO::NoSignedWrap), + ConstantRange(APInt::getSignedMinValue(32) + 5, + APInt::getSignedMinValue(32))); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusFiveToMinusTwo, OBO::NoUnsignedWrap), + ConstantRange(APInt(32, 0), APInt(32, 2))); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusFiveToMinusTwo, + OBO::NoUnsignedWrap | OBO::NoSignedWrap), + ConstantRange(APInt(32, 0), APInt(32, 2))); + + ConstantRange MinusOneToOne(APInt(32, -1), APInt(32, 2)); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusOneToOne, OBO::NoSignedWrap), + ConstantRange(APInt::getSignedMinValue(32) + 1, + APInt::getSignedMinValue(32) - 1)); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusOneToOne, OBO::NoUnsignedWrap), + ConstantRange(APInt(32, 0), APInt(32, 1))); + EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Add, MinusOneToOne, + OBO::NoUnsignedWrap | OBO::NoSignedWrap), + ConstantRange(APInt(32, 0), APInt(32, 1))); } } // anonymous namespace |