llvm.org GIT mirror llvm / 24352fc
[ConstantRangeTest] Generalize intersection testing code; NFC Extract the exhaustive intersection tests into a separate function, so that it may be reused for unions as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357874 91177308-0d34-0410-b5e6-96231b3b80d8 Nikita Popov 6 months ago
1 changed file(s) with 17 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
362362 EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
363363 }
364364
365 TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
365 template
366 void testBinarySetOperationExhaustive(Fn1 OpFn, Fn2 InResultFn) {
366367 unsigned Bits = 4;
367368 EnumerateTwoConstantRanges(Bits,
368369 [=](const ConstantRange &CR1, const ConstantRange &CR2) {
378379
379380 APInt Num(Bits, 0);
380381 for (unsigned I = 0, Limit = 1 << Bits; I < Limit; ++I, ++Num) {
381 if (!CR1.contains(Num) || !CR2.contains(Num)) {
382 if (!InResultFn(CR1, CR2, Num)) {
382383 if (HaveRange3)
383384 HaveInterrupt3 = true;
384385 else if (HaveRange2)
408409
409410 assert(!HaveInterrupt3 && "Should have at most three ranges");
410411
411 ConstantRange SmallestCR =
412 CR1.intersectWith(CR2, ConstantRange::Smallest);
413 ConstantRange UnsignedCR =
414 CR1.intersectWith(CR2, ConstantRange::Unsigned);
415 ConstantRange SignedCR =
416 CR1.intersectWith(CR2, ConstantRange::Signed);
412 ConstantRange SmallestCR = OpFn(CR1, CR2, ConstantRange::Smallest);
413 ConstantRange UnsignedCR = OpFn(CR1, CR2, ConstantRange::Unsigned);
414 ConstantRange SignedCR = OpFn(CR1, CR2, ConstantRange::Signed);
417415
418416 if (!HaveRange1) {
419417 EXPECT_TRUE(SmallestCR.isEmptySet());
488486 EXPECT_EQ(Variant2, SignedCR);
489487 else
490488 EXPECT_TRUE(Variant1 == SignedCR || Variant2 == SignedCR);
489 });
490 }
491
492 TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
493 testBinarySetOperationExhaustive(
494 [](const ConstantRange &CR1, const ConstantRange &CR2,
495 ConstantRange::PreferredRangeType Type) {
496 return CR1.intersectWith(CR2, Type);
497 },
498 [](const ConstantRange &CR1, const ConstantRange &CR2, const APInt &N) {
499 return CR1.contains(N) && CR2.contains(N);
491500 });
492501 }
493502