diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2023-04-18 07:36:37 -0400 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2023-04-26 06:22:30 -0400 |
commit | be8aafa1e2178810f06e5390f58058c31f16f66e (patch) | |
tree | 26da5cf547f70892103786e88b133878803c4bc9 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | be713870752f47272a3cf938546a3592553e55fa (diff) | |
download | llvm-be8aafa1e2178810f06e5390f58058c31f16f66e.zip llvm-be8aafa1e2178810f06e5390f58058c31f16f66e.tar.gz llvm-be8aafa1e2178810f06e5390f58058c31f16f66e.tar.bz2 |
ValueTracking: fdiv sign handling in computeKnownFPClass
Copy what cannotBeOrderedLessThanZeroImpl checks for fdiv.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 249b228..b47e7af 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4760,7 +4760,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, Known.knownNot(fcSubnormal); if (IID == Intrinsic::experimental_constrained_uitofp) - Known.signBitIsZero(); + Known.signBitMustBeZero(); // TODO: Copy inf handling from instructions break; @@ -4824,30 +4824,37 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, break; } case Instruction::FDiv: { + // X / X is always exactly 1.0 or a NaN. + if (Op->getOperand(0) == Op->getOperand(1)) { + // TODO: Could filter out snan if we inspect the operand + Known.KnownFPClasses = fcNan | fcPosNormal; + break; + } + const bool WantNan = (InterestedClasses & fcNan) != fcNone; - if (!WantNan) + const bool WantNegative = (InterestedClasses & fcNegative) != fcNone; + if (!WantNan && !WantNegative) break; // TODO: FRem KnownFPClass KnownLHS, KnownRHS; computeKnownFPClass(Op->getOperand(1), DemandedElts, - fcNan | fcInf | fcZero | fcSubnormal, KnownRHS, + fcNan | fcInf | fcZero | fcNegative, KnownRHS, Depth + 1, Q, TLI); - bool KnowSomethingUseful = KnownRHS.isKnownNeverNaN() || - KnownRHS.isKnownNeverInfinity() || - KnownRHS.isKnownNeverZero(); + bool KnowSomethingUseful = + KnownRHS.isKnownNeverNaN() || KnownRHS.isKnownNever(fcNegative); if (KnowSomethingUseful) { computeKnownFPClass(Op->getOperand(0), DemandedElts, - fcNan | fcInf | fcZero, KnownLHS, Depth + 1, Q, TLI); + fcNan | fcInf | fcZero | fcNegative, KnownLHS, + Depth + 1, Q, TLI); } const Function *F = cast<Instruction>(Op)->getFunction(); // Only 0/0, Inf/Inf, Inf REM x and x REM 0 produce NaN. - // TODO: Track sign bit. if (KnownLHS.isKnownNeverNaN() && KnownRHS.isKnownNeverNaN() && (KnownLHS.isKnownNeverInfinity() || KnownRHS.isKnownNeverInfinity()) && (KnownLHS.isKnownNeverLogicalZero(*F, Op->getType()) || @@ -4855,6 +4862,11 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, Known.knownNot(fcNan); } + // X / -0.0 is -Inf (or NaN). + // +X / +X is +X + if (KnownLHS.isKnownNever(fcNegative) && KnownRHS.isKnownNever(fcNegative)) + Known.knownNot(fcNegative); + break; } case Instruction::FPExt: { @@ -4892,7 +4904,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, // sitofp and uitofp turn into +0.0 for zero. Known.knownNot(fcNegZero); if (Op->getOpcode() == Instruction::UIToFP) - Known.signBitIsZero(); + Known.signBitMustBeZero(); if (InterestedClasses & fcInf) { // Get width of largest magnitude integer (remove a bit if signed). |