diff options
author | Tim Shen <timshen91@gmail.com> | 2018-06-26 18:54:10 +0000 |
---|---|---|
committer | Tim Shen <timshen91@gmail.com> | 2018-06-26 18:54:10 +0000 |
commit | b32823cbe979a8115adb097d6ef0017b0e9a7f63 (patch) | |
tree | e1f3f170d78c3713e8b0b6e2309c036dccadcf9d /llvm/unittests/IR/ConstantRangeTest.cpp | |
parent | 2c1a570aabc184e93f160992c3fe3eab8f884f74 (diff) | |
download | bcm5719-llvm-b32823cbe979a8115adb097d6ef0017b0e9a7f63.tar.gz bcm5719-llvm-b32823cbe979a8115adb097d6ef0017b0e9a7f63.zip |
[ConstantRange] Add support of mul in makeGuaranteedNoWrapRegion.
Summary: This is trying to add support for r334428.
Reviewers: sanjoy
Subscribers: jlebar, hiraditya, bixia, llvm-commits
Differential Revision: https://reviews.llvm.org/D48399
llvm-svn: 335646
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 351256d4993..c0a30f1b4d9 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -1021,4 +1021,103 @@ TEST(ConstantRange, GetEquivalentICmp) { EXPECT_EQ(RHS, APInt(32, -1)); } +TEST(ConstantRange, MakeGuaranteedNoWrapRegionMulUnsignedSingleValue) { + typedef OverflowingBinaryOperator OBO; + + for (uint64_t I = std::numeric_limits<uint8_t>::min(); + I <= std::numeric_limits<uint8_t>::max(); I++) { + auto Range = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, ConstantRange(APInt(8, I), APInt(8, I + 1)), + OBO::NoUnsignedWrap); + + for (uint64_t V = std::numeric_limits<uint8_t>::min(); + V <= std::numeric_limits<uint8_t>::max(); V++) { + bool Overflow; + (void)APInt(8, I).umul_ov(APInt(8, V), Overflow); + EXPECT_EQ(!Overflow, Range.contains(APInt(8, V))); + } + } +} + +TEST(ConstantRange, MakeGuaranteedNoWrapRegionMulSignedSingleValue) { + typedef OverflowingBinaryOperator OBO; + + for (int64_t I = std::numeric_limits<int8_t>::min(); + I <= std::numeric_limits<int8_t>::max(); I++) { + auto Range = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, + ConstantRange(APInt(8, I, /*isSigned=*/true), + APInt(8, I + 1, /*isSigned=*/true)), + OBO::NoSignedWrap); + + for (int64_t V = std::numeric_limits<int8_t>::min(); + V <= std::numeric_limits<int8_t>::max(); V++) { + bool Overflow; + (void)APInt(8, I, /*isSigned=*/true) + .smul_ov(APInt(8, V, /*isSigned=*/true), Overflow); + EXPECT_EQ(!Overflow, Range.contains(APInt(8, V, /*isSigned=*/true))); + } + } +} + +TEST(ConstantRange, MakeGuaranteedNoWrapRegionMulUnsignedAndSignedSingleValue) { + typedef OverflowingBinaryOperator OBO; + + for (uint64_t I = std::numeric_limits<uint8_t>::min(); + I <= std::numeric_limits<uint8_t>::max(); I++) { + auto Range = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, ConstantRange(APInt(8, I), APInt(8, I + 1)), + OBO::NoUnsignedWrap | OBO::NoSignedWrap); + + for (uint64_t V = std::numeric_limits<uint8_t>::min(); + V <= std::numeric_limits<uint8_t>::max(); V++) { + bool UOverflow; + (void)APInt(8, I).umul_ov(APInt(8, V), UOverflow); + bool SOverflow; + (void)APInt(8, I).smul_ov(APInt(8, V), SOverflow); + EXPECT_EQ(!(UOverflow || SOverflow), Range.contains(APInt(8, V))); + } + } +} + +TEST(ConstantRange, MakeGuaranteedNoWrapRegionMulUnsignedRange) { + typedef OverflowingBinaryOperator OBO; + + for (uint64_t Lo = std::numeric_limits<uint8_t>::min(); + Lo <= std::numeric_limits<uint8_t>::max(); Lo++) { + for (uint64_t Hi = Lo; Hi <= std::numeric_limits<uint8_t>::max(); Hi++) { + EXPECT_EQ( + ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, ConstantRange(APInt(8, Lo), APInt(8, Hi + 1)), + OBO::NoUnsignedWrap), + ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, ConstantRange(APInt(8, Hi), APInt(8, Hi + 1)), + OBO::NoUnsignedWrap)); + } + } +} + +TEST(ConstantRange, MakeGuaranteedNoWrapRegionMulSignedRange) { + typedef OverflowingBinaryOperator OBO; + + int Lo = -12, Hi = 16; + auto Range = ConstantRange::makeGuaranteedNoWrapRegion( + Instruction::Mul, + ConstantRange(APInt(8, Lo, /*isSigned=*/true), + APInt(8, Hi + 1, /*isSigned=*/true)), + OBO::NoSignedWrap); + + for (int64_t V = std::numeric_limits<int8_t>::min(); + V <= std::numeric_limits<int8_t>::max(); V++) { + bool AnyOverflow = false; + for (int64_t I = Lo; I <= Hi; I++) { + bool Overflow; + (void)APInt(8, I, /*isSigned=*/true) + .smul_ov(APInt(8, V, /*isSigned=*/true), Overflow); + AnyOverflow |= Overflow; + } + EXPECT_EQ(!AnyOverflow, Range.contains(APInt(8, V, /*isSigned=*/true))); + } +} + } // anonymous namespace |