Skip to content

Commit

Permalink
[ConstantFPRange] Address review comments. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Oct 2, 2024
1 parent 23f064f commit 5da6f23
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/IR/ConstantFPRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ ConstantFPRange ConstantFPRange::getNonNaN(const fltSemantics &Sem) {
/*MayBeQNaN=*/false, /*MayBeSNaN=*/false);
}

/// Return true for ULT/UGT/OLT/OGT
static bool fcmpPredExcludesEqual(FCmpInst::Predicate Pred) {
return !(Pred & FCmpInst::FCMP_OEQ);
}

/// Return [-inf, V) or [-inf, V]
static ConstantFPRange makeLessThan(APFloat V, FCmpInst::Predicate Pred) {
const fltSemantics &Sem = V.getSemantics();
if (FCmpInst::isFalseWhenEqual(FCmpInst::getOrderedPredicate(Pred))) {
if (fcmpPredExcludesEqual(Pred)) {
if (V.isNegInfinity())
return ConstantFPRange::getEmpty(Sem);
V.next(/*nextDown=*/true);
Expand All @@ -123,7 +128,7 @@ static ConstantFPRange makeLessThan(APFloat V, FCmpInst::Predicate Pred) {
/// Return (V, +inf] or [V, +inf]
static ConstantFPRange makeGreaterThan(APFloat V, FCmpInst::Predicate Pred) {
const fltSemantics &Sem = V.getSemantics();
if (FCmpInst::isFalseWhenEqual(FCmpInst::getOrderedPredicate(Pred))) {
if (fcmpPredExcludesEqual(Pred)) {
if (V.isPosInfinity())
return ConstantFPRange::getEmpty(Sem);
V.next(/*nextDown=*/false);
Expand All @@ -135,7 +140,7 @@ static ConstantFPRange makeGreaterThan(APFloat V, FCmpInst::Predicate Pred) {
/// Make sure that +0/-0 are both included in the range.
static ConstantFPRange extendZeroIfEqual(const ConstantFPRange &CR,
FCmpInst::Predicate Pred) {
if (FCmpInst::isFalseWhenEqual(FCmpInst::getOrderedPredicate(Pred)))
if (fcmpPredExcludesEqual(Pred))
return CR;

APFloat Lower = CR.getLower();
Expand Down

0 comments on commit 5da6f23

Please sign in to comment.