@@ -539,4 +539,65 @@ TEST_F(ConstantFPRangeTest, makeSatisfyingFCmpRegion) {
539
539
}
540
540
}
541
541
542
+ TEST_F (ConstantFPRangeTest, fcmp) {
543
+ std::vector<ConstantFPRange> InterestingRanges;
544
+ const fltSemantics &Sem = APFloat::Float8E4M3 ();
545
+ auto FpImm = [&](double V) {
546
+ bool ignored;
547
+ APFloat APF (V);
548
+ APF.convert (Sem, APFloat::rmNearestTiesToEven, &ignored);
549
+ return APF;
550
+ };
551
+
552
+ InterestingRanges.push_back (ConstantFPRange::getEmpty (Sem));
553
+ InterestingRanges.push_back (ConstantFPRange::getFull (Sem));
554
+ InterestingRanges.push_back (ConstantFPRange::getFinite (Sem));
555
+ InterestingRanges.push_back (ConstantFPRange (FpImm (1.0 )));
556
+ InterestingRanges.push_back (
557
+ ConstantFPRange (APFloat::getZero (Sem, /* Negative=*/ false )));
558
+ InterestingRanges.push_back (
559
+ ConstantFPRange (APFloat::getZero (Sem, /* Negative=*/ true )));
560
+ InterestingRanges.push_back (
561
+ ConstantFPRange (APFloat::getInf (Sem, /* Negative=*/ false )));
562
+ InterestingRanges.push_back (
563
+ ConstantFPRange (APFloat::getInf (Sem, /* Negative=*/ true )));
564
+ InterestingRanges.push_back (
565
+ ConstantFPRange (APFloat::getSmallest (Sem, /* Negative=*/ false )));
566
+ InterestingRanges.push_back (
567
+ ConstantFPRange (APFloat::getSmallest (Sem, /* Negative=*/ true )));
568
+ InterestingRanges.push_back (
569
+ ConstantFPRange (APFloat::getLargest (Sem, /* Negative=*/ false )));
570
+ InterestingRanges.push_back (
571
+ ConstantFPRange (APFloat::getLargest (Sem, /* Negative=*/ true )));
572
+ InterestingRanges.push_back (
573
+ ConstantFPRange::getNaNOnly (Sem, /* MayBeQNaN=*/ true , /* MayBeSNaN=*/ true ));
574
+ InterestingRanges.push_back (
575
+ ConstantFPRange::getNonNaN (FpImm (0.0 ), FpImm (1.0 )));
576
+ InterestingRanges.push_back (
577
+ ConstantFPRange::getNonNaN (FpImm (2.0 ), FpImm (3.0 )));
578
+ InterestingRanges.push_back (
579
+ ConstantFPRange::getNonNaN (FpImm (-1.0 ), FpImm (1.0 )));
580
+ InterestingRanges.push_back (
581
+ ConstantFPRange::getNonNaN (FpImm (-1.0 ), FpImm (-0.0 )));
582
+ InterestingRanges.push_back (ConstantFPRange::getNonNaN (
583
+ APFloat::getInf (Sem, /* Negative=*/ true ), FpImm (-1.0 )));
584
+ InterestingRanges.push_back (ConstantFPRange::getNonNaN (
585
+ FpImm (1.0 ), APFloat::getInf (Sem, /* Negative=*/ false )));
586
+
587
+ for (auto &LHS : InterestingRanges) {
588
+ for (auto &RHS : InterestingRanges) {
589
+ for (auto Pred : FCmpInst::predicates ()) {
590
+ if (LHS.fcmp (Pred, RHS)) {
591
+ EnumerateValuesInConstantFPRange (LHS, [&](const APFloat &LHSC) {
592
+ EnumerateValuesInConstantFPRange (RHS, [&](const APFloat &RHSC) {
593
+ EXPECT_TRUE (FCmpInst::compare (LHSC, RHSC, Pred))
594
+ << LHS << " " << Pred << " " << RHS << " doesn't hold" ;
595
+ });
596
+ });
597
+ }
598
+ }
599
+ }
600
+ }
601
+ }
602
+
542
603
} // anonymous namespace
0 commit comments