Skip to content

Commit

Permalink
[ConstantFPRange] Add unittests for fcmp. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Oct 2, 2024
1 parent 2633b93 commit 3a98c87
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions llvm/unittests/IR/ConstantFPRangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,65 @@ TEST_F(ConstantFPRangeTest, makeSatisfyingFCmpRegion) {
}
}

TEST_F(ConstantFPRangeTest, fcmp) {
std::vector<ConstantFPRange> InterestingRanges;
const fltSemantics &Sem = APFloat::Float8E4M3();
auto FpImm = [&](double V) {
bool ignored;
APFloat APF(V);
APF.convert(Sem, APFloat::rmNearestTiesToEven, &ignored);
return APF;
};

InterestingRanges.push_back(ConstantFPRange::getEmpty(Sem));
InterestingRanges.push_back(ConstantFPRange::getFull(Sem));
InterestingRanges.push_back(ConstantFPRange::getFinite(Sem));
InterestingRanges.push_back(ConstantFPRange(FpImm(1.0)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getZero(Sem, /*Negative=*/false)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getZero(Sem, /*Negative=*/true)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getInf(Sem, /*Negative=*/false)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getInf(Sem, /*Negative=*/true)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getSmallest(Sem, /*Negative=*/false)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getSmallest(Sem, /*Negative=*/true)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getLargest(Sem, /*Negative=*/false)));
InterestingRanges.push_back(
ConstantFPRange(APFloat::getLargest(Sem, /*Negative=*/true)));
InterestingRanges.push_back(
ConstantFPRange::getNaNOnly(Sem, /*MayBeQNaN=*/true, /*MayBeSNaN=*/true));
InterestingRanges.push_back(
ConstantFPRange::getNonNaN(FpImm(0.0), FpImm(1.0)));
InterestingRanges.push_back(
ConstantFPRange::getNonNaN(FpImm(2.0), FpImm(3.0)));
InterestingRanges.push_back(
ConstantFPRange::getNonNaN(FpImm(-1.0), FpImm(1.0)));
InterestingRanges.push_back(
ConstantFPRange::getNonNaN(FpImm(-1.0), FpImm(-0.0)));
InterestingRanges.push_back(ConstantFPRange::getNonNaN(
APFloat::getInf(Sem, /*Negative=*/true), FpImm(-1.0)));
InterestingRanges.push_back(ConstantFPRange::getNonNaN(
FpImm(1.0), APFloat::getInf(Sem, /*Negative=*/false)));

for (auto &LHS : InterestingRanges) {
for (auto &RHS : InterestingRanges) {
for (auto Pred : FCmpInst::predicates()) {
if (LHS.fcmp(Pred, RHS)) {
EnumerateValuesInConstantFPRange(LHS, [&](const APFloat &LHSC) {
EnumerateValuesInConstantFPRange(RHS, [&](const APFloat &RHSC) {
EXPECT_TRUE(FCmpInst::compare(LHSC, RHSC, Pred))
<< LHS << " " << Pred << " " << RHS << " doesn't hold";
});
});
}
}
}
}
}

} // anonymous namespace

0 comments on commit 3a98c87

Please sign in to comment.