Skip to content

Commit a3a253d

Browse files
authored
[ConstantFPRange] Implement ConstantFPRange::makeExactFCmpRegion (llvm#111490)
Note: The current implementation doesn't return optimal result for `fcmp one/une x, +/-inf` since we don't handle this case in llvm#110891. Maybe we can make it optimal after seeing some real-world cases.
1 parent a11509c commit a3a253d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llvm/lib/IR/ConstantFPRange.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ ConstantFPRange::makeSatisfyingFCmpRegion(FCmpInst::Predicate Pred,
268268
std::optional<ConstantFPRange>
269269
ConstantFPRange::makeExactFCmpRegion(FCmpInst::Predicate Pred,
270270
const APFloat &Other) {
271-
return std::nullopt;
271+
if ((Pred == FCmpInst::FCMP_UNE || Pred == FCmpInst::FCMP_ONE) &&
272+
!Other.isNaN())
273+
return std::nullopt;
274+
return makeSatisfyingFCmpRegion(Pred, ConstantFPRange(Other));
272275
}
273276

274277
bool ConstantFPRange::fcmp(FCmpInst::Predicate Pred,

llvm/unittests/IR/ConstantFPRangeTest.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -743,4 +743,28 @@ TEST_F(ConstantFPRangeTest, fcmp) {
743743
}
744744
}
745745

746+
TEST_F(ConstantFPRangeTest, makeExactFCmpRegion) {
747+
for (auto Pred : FCmpInst::predicates()) {
748+
EnumerateValuesInConstantFPRange(
749+
ConstantFPRange::getFull(APFloat::Float8E4M3()),
750+
[Pred](const APFloat &V) {
751+
std::optional<ConstantFPRange> Res =
752+
ConstantFPRange::makeExactFCmpRegion(Pred, V);
753+
ConstantFPRange Allowed =
754+
ConstantFPRange::makeAllowedFCmpRegion(Pred, ConstantFPRange(V));
755+
ConstantFPRange Satisfying =
756+
ConstantFPRange::makeSatisfyingFCmpRegion(Pred,
757+
ConstantFPRange(V));
758+
if (Allowed == Satisfying)
759+
EXPECT_EQ(Res, Allowed) << "Wrong result for makeExactFCmpRegion("
760+
<< Pred << ", " << V << ").";
761+
else
762+
EXPECT_FALSE(Res.has_value())
763+
<< "Wrong result for makeExactFCmpRegion(" << Pred << ", " << V
764+
<< ").";
765+
},
766+
/*IgnoreNaNPayload=*/true);
767+
}
768+
}
769+
746770
} // anonymous namespace

0 commit comments

Comments
 (0)