[llvm] r375369 - [ConstantRange] Optimize nowrap region test, remove redundant tests; NFC
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 20 11:59:15 PDT 2019
Author: nikic
Date: Sun Oct 20 11:59:14 2019
New Revision: 375369
URL: http://llvm.org/viewvc/llvm-project?rev=375369&view=rev
Log:
[ConstantRange] Optimize nowrap region test, remove redundant tests; NFC
Enumerate one less constant range in TestNoWrapRegionExhaustive,
which was unnecessary. This allows us to bump the bit count from
3 to 5 while keeping reasonable timing.
Drop four tests for multiply nowrap regions, as these cover subsets
of the exhaustive test. They do use a wider bitwidth, but I don't
think it's worthwhile to have them additionally now.
Modified:
llvm/trunk/unittests/IR/ConstantRangeTest.cpp
Modified: llvm/trunk/unittests/IR/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantRangeTest.cpp?rev=375369&r1=375368&r2=375369&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantRangeTest.cpp Sun Oct 20 11:59:14 2019
@@ -1537,32 +1537,31 @@ TEST(ConstantRange, MakeGuaranteedNoWrap
template<typename Fn>
void TestNoWrapRegionExhaustive(Instruction::BinaryOps BinOp,
unsigned NoWrapKind, Fn OverflowFn) {
- // When using 4 bits this test needs ~3s on a debug build.
- unsigned Bits = 3;
- EnumerateTwoConstantRanges(Bits,
- [&](const ConstantRange &CR1, const ConstantRange &CR2) {
- if (CR2.isEmptySet())
- return;
-
- ConstantRange NoWrap =
- ConstantRange::makeGuaranteedNoWrapRegion(BinOp, CR2, NoWrapKind);
- ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
- bool NoOverflow = true;
- bool Overflow = true;
- ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
- if (OverflowFn(N1, N2))
- NoOverflow = false;
- else
- Overflow = false;
- });
- EXPECT_EQ(NoOverflow, NoWrap.contains(N1));
-
- // The no-wrap range is exact for single-element ranges.
- if (CR2.isSingleElement()) {
- EXPECT_EQ(Overflow, !NoWrap.contains(N1));
- }
- });
- });
+ unsigned Bits = 5;
+ EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) {
+ if (CR.isEmptySet())
+ return;
+
+ ConstantRange NoWrap =
+ ConstantRange::makeGuaranteedNoWrapRegion(BinOp, CR, NoWrapKind);
+ ConstantRange Full = ConstantRange::getFull(Bits);
+ ForeachNumInConstantRange(Full, [&](const APInt &N1) {
+ bool NoOverflow = true;
+ bool Overflow = true;
+ ForeachNumInConstantRange(CR, [&](const APInt &N2) {
+ if (OverflowFn(N1, N2))
+ NoOverflow = false;
+ else
+ Overflow = false;
+ });
+ EXPECT_EQ(NoOverflow, NoWrap.contains(N1));
+
+ // The no-wrap range is exact for single-element ranges.
+ if (CR.isSingleElement()) {
+ EXPECT_EQ(Overflow, !NoWrap.contains(N1));
+ }
+ });
+ });
}
// Show that makeGuaranteedNoWrapRegion() is maximal, and for single-element
@@ -1694,85 +1693,6 @@ 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, 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)));
- }
-}
-
#define EXPECT_MAY_OVERFLOW(op) \
EXPECT_EQ(ConstantRange::OverflowResult::MayOverflow, (op))
#define EXPECT_ALWAYS_OVERFLOWS_LOW(op) \
More information about the llvm-commits
mailing list