Skip to content

Commit 1f7034c

Browse files
committed
refactor test
1 parent 3faba75 commit 1f7034c

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

llvm/unittests/Support/KnownBitsTest.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,6 @@ TEST(KnownBitsTest, ICmpExhaustive) {
561561
unsigned Bits = 4;
562562
ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
563563
ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
564-
if (Known1.hasConflict() || Known2.hasConflict())
565-
return;
566-
567564
bool AllEQ = true, NoneEQ = true;
568565
bool AllNE = true, NoneNE = true;
569566
bool AllUGT = true, NoneUGT = true;
@@ -611,6 +608,9 @@ TEST(KnownBitsTest, ICmpExhaustive) {
611608
std::optional<bool> KnownSLT = KnownBits::slt(Known1, Known2);
612609
std::optional<bool> KnownSLE = KnownBits::sle(Known1, Known2);
613610

611+
if (Known1.hasConflict() || Known2.hasConflict())
612+
return;
613+
614614
EXPECT_EQ(AllEQ || NoneEQ, KnownEQ.has_value());
615615
EXPECT_EQ(AllNE || NoneNE, KnownNE.has_value());
616616
EXPECT_EQ(AllUGT || NoneUGT, KnownUGT.has_value());
@@ -650,62 +650,58 @@ TEST(KnownBitsTest, ICmpExhaustive) {
650650
TEST(KnownBitsTest, GetMinMaxVal) {
651651
unsigned Bits = 4;
652652
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
653-
if (Known.hasConflict())
654-
return;
655-
656653
APInt Min = APInt::getMaxValue(Bits);
657654
APInt Max = APInt::getMinValue(Bits);
658655
ForeachNumInKnownBits(Known, [&](const APInt &N) {
659656
Min = APIntOps::umin(Min, N);
660657
Max = APIntOps::umax(Max, N);
661658
});
662-
EXPECT_EQ(Min, Known.getMinValue());
663-
EXPECT_EQ(Max, Known.getMaxValue());
659+
if (!Known.hasConflict()) {
660+
EXPECT_EQ(Min, Known.getMinValue());
661+
EXPECT_EQ(Max, Known.getMaxValue());
662+
}
664663
});
665664
}
666665

667666
TEST(KnownBitsTest, GetSignedMinMaxVal) {
668667
unsigned Bits = 4;
669668
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
670-
if (Known.hasConflict())
671-
return;
672-
673669
APInt Min = APInt::getSignedMaxValue(Bits);
674670
APInt Max = APInt::getSignedMinValue(Bits);
675671
ForeachNumInKnownBits(Known, [&](const APInt &N) {
676672
Min = APIntOps::smin(Min, N);
677673
Max = APIntOps::smax(Max, N);
678674
});
679-
EXPECT_EQ(Min, Known.getSignedMinValue());
680-
EXPECT_EQ(Max, Known.getSignedMaxValue());
675+
if (!Known.hasConflict()) {
676+
EXPECT_EQ(Min, Known.getSignedMinValue());
677+
EXPECT_EQ(Max, Known.getSignedMaxValue());
678+
}
681679
});
682680
}
683681

684682
TEST(KnownBitsTest, CountMaxActiveBits) {
685683
unsigned Bits = 4;
686684
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
687-
if (Known.hasConflict())
688-
return;
689-
690685
unsigned Expected = 0;
691686
ForeachNumInKnownBits(Known, [&](const APInt &N) {
692687
Expected = std::max(Expected, N.getActiveBits());
693688
});
694-
EXPECT_EQ(Expected, Known.countMaxActiveBits());
689+
if (!Known.hasConflict()) {
690+
EXPECT_EQ(Expected, Known.countMaxActiveBits());
691+
}
695692
});
696693
}
697694

698695
TEST(KnownBitsTest, CountMaxSignificantBits) {
699696
unsigned Bits = 4;
700697
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
701-
if (Known.hasConflict())
702-
return;
703-
704698
unsigned Expected = 0;
705699
ForeachNumInKnownBits(Known, [&](const APInt &N) {
706700
Expected = std::max(Expected, N.getSignificantBits());
707701
});
708-
EXPECT_EQ(Expected, Known.countMaxSignificantBits());
702+
if (!Known.hasConflict()) {
703+
EXPECT_EQ(Expected, Known.countMaxSignificantBits());
704+
}
709705
});
710706
}
711707

@@ -741,9 +737,6 @@ TEST(KnownBitsTest, SExtInReg) {
741737
unsigned Bits = 4;
742738
for (unsigned FromBits = 1; FromBits <= Bits; ++FromBits) {
743739
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
744-
if (Known.hasConflict())
745-
return;
746-
747740
APInt CommonOne = APInt::getAllOnes(Bits);
748741
APInt CommonZero = APInt::getAllOnes(Bits);
749742
unsigned ExtBits = Bits - FromBits;
@@ -754,8 +747,10 @@ TEST(KnownBitsTest, SExtInReg) {
754747
CommonZero &= ~Ext;
755748
});
756749
KnownBits KnownSExtInReg = Known.sextInReg(FromBits);
757-
EXPECT_EQ(CommonOne, KnownSExtInReg.One);
758-
EXPECT_EQ(CommonZero, KnownSExtInReg.Zero);
750+
if (!Known.hasConflict()) {
751+
EXPECT_EQ(CommonOne, KnownSExtInReg.One);
752+
EXPECT_EQ(CommonZero, KnownSExtInReg.Zero);
753+
}
759754
});
760755
}
761756
}
@@ -764,17 +759,16 @@ TEST(KnownBitsTest, CommonBitsSet) {
764759
unsigned Bits = 4;
765760
ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
766761
ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
767-
if (Known1.hasConflict() || Known2.hasConflict())
768-
return;
769-
770762
bool HasCommonBitsSet = false;
771763
ForeachNumInKnownBits(Known1, [&](const APInt &N1) {
772764
ForeachNumInKnownBits(Known2, [&](const APInt &N2) {
773765
HasCommonBitsSet |= N1.intersects(N2);
774766
});
775767
});
776-
EXPECT_EQ(!HasCommonBitsSet,
777-
KnownBits::haveNoCommonBitsSet(Known1, Known2));
768+
if (!Known1.hasConflict() && !Known2.hasConflict()) {
769+
EXPECT_EQ(!HasCommonBitsSet,
770+
KnownBits::haveNoCommonBitsSet(Known1, Known2));
771+
}
778772
});
779773
});
780774
}

0 commit comments

Comments
 (0)