[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375369 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp
index 58a2516..fa67032 100644
--- a/unittests/IR/ConstantRangeTest.cpp
+++ b/unittests/IR/ConstantRangeTest.cpp
@@ -1537,32 +1537,31 @@
 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;
+  unsigned Bits = 5;
+  EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) {
+    if (CR.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));
-          }
-        });
+    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 @@
   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) \