Skip to content

ValueTracking: Handle minimumnum and maximumnum in computeKnownFPClass #138737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5357,7 +5357,9 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
case Intrinsic::maxnum:
case Intrinsic::minnum:
case Intrinsic::minimum:
case Intrinsic::maximum: {
case Intrinsic::maximum:
case Intrinsic::minimumnum:
case Intrinsic::maximumnum: {
KnownFPClass KnownLHS, KnownRHS;
computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
KnownLHS, Depth + 1, Q);
Expand All @@ -5368,10 +5370,12 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
Known = KnownLHS | KnownRHS;

// If either operand is not NaN, the result is not NaN.
if (NeverNaN && (IID == Intrinsic::minnum || IID == Intrinsic::maxnum))
if (NeverNaN &&
(IID == Intrinsic::minnum || IID == Intrinsic::maxnum ||
IID == Intrinsic::minimumnum || IID == Intrinsic::maximumnum))
Known.knownNot(fcNan);

if (IID == Intrinsic::maxnum) {
if (IID == Intrinsic::maxnum || IID == Intrinsic::maximumnum) {
// If at least one operand is known to be positive, the result must be
// positive.
if ((KnownLHS.cannotBeOrderedLessThanZero() &&
Expand All @@ -5385,21 +5389,22 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
if (KnownLHS.cannotBeOrderedLessThanZero() ||
KnownRHS.cannotBeOrderedLessThanZero())
Known.knownNot(KnownFPClass::OrderedLessThanZeroMask);
} else if (IID == Intrinsic::minnum) {
} else if (IID == Intrinsic::minnum || IID == Intrinsic::minimumnum) {
// If at least one operand is known to be negative, the result must be
// negative.
if ((KnownLHS.cannotBeOrderedGreaterThanZero() &&
KnownLHS.isKnownNeverNaN()) ||
(KnownRHS.cannotBeOrderedGreaterThanZero() &&
KnownRHS.isKnownNeverNaN()))
Known.knownNot(KnownFPClass::OrderedGreaterThanZeroMask);
} else {
} else if (IID == Intrinsic::minimum) {
// If at least one operand is known to be negative, the result must be
// negative.
if (KnownLHS.cannotBeOrderedGreaterThanZero() ||
KnownRHS.cannotBeOrderedGreaterThanZero())
Known.knownNot(KnownFPClass::OrderedGreaterThanZeroMask);
}
} else
llvm_unreachable("unhandled intrinsic");

// Fixup zero handling if denormals could be returned as a zero.
//
Expand Down Expand Up @@ -5427,15 +5432,20 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
Known.signBitMustBeOne();
else
Known.signBitMustBeZero();
} else if ((IID == Intrinsic::maximum || IID == Intrinsic::minimum) ||
} else if ((IID == Intrinsic::maximum || IID == Intrinsic::minimum ||
IID == Intrinsic::maximumnum ||
IID == Intrinsic::minimumnum) ||
// FIXME: Should be using logical zero versions
((KnownLHS.isKnownNeverNegZero() ||
KnownRHS.isKnownNeverPosZero()) &&
(KnownLHS.isKnownNeverPosZero() ||
KnownRHS.isKnownNeverNegZero()))) {
if ((IID == Intrinsic::maximum || IID == Intrinsic::maxnum) &&
if ((IID == Intrinsic::maximum || IID == Intrinsic::maximumnum ||
IID == Intrinsic::maxnum) &&
(KnownLHS.SignBit == false || KnownRHS.SignBit == false))
Known.signBitMustBeZero();
else if ((IID == Intrinsic::minimum || IID == Intrinsic::minnum) &&
else if ((IID == Intrinsic::minimum || IID == Intrinsic::minimumnum ||
IID == Intrinsic::minnum) &&
(KnownLHS.SignBit == true || KnownRHS.SignBit == true))
Known.signBitMustBeOne();
}
Expand Down
Loading
Loading