aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2023-04-09 07:16:04 -0400
committerMatt Arsenault <arsenm2@gmail.com>2023-04-26 05:20:55 -0400
commit2ff52ea4ad0ae1ee0b349525d9dbed9efbbae788 (patch)
treecd0ebad9fcdee739d882d6ffec97238d7c281404 /llvm/lib/Analysis/ValueTracking.cpp
parent2a8db0be9e57cc49db34b3f39e2171099317f929 (diff)
downloadllvm-2ff52ea4ad0ae1ee0b349525d9dbed9efbbae788.zip
llvm-2ff52ea4ad0ae1ee0b349525d9dbed9efbbae788.tar.gz
llvm-2ff52ea4ad0ae1ee0b349525d9dbed9efbbae788.tar.bz2
ValueTracking: Handle powi in computeKnownFPClass
Extract the handling from cannotBeOrderedLessThanZeroImpl and avoid the mentioned -0 bug.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index cc3f672..fa5c214 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4693,6 +4693,36 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
break;
}
+ case Intrinsic::powi: {
+ if ((InterestedClasses & fcNegative) == fcNone)
+ break;
+
+ const Value *Exp = II->getArgOperand(1);
+ unsigned BitWidth =
+ Exp->getType()->getScalarType()->getIntegerBitWidth();
+ KnownBits ExponentKnownBits(BitWidth);
+ computeKnownBits(Exp, DemandedElts, ExponentKnownBits, Depth + 1, Q);
+
+ if (ExponentKnownBits.Zero[0]) { // Is even
+ Known.knownNot(fcNegative);
+ break;
+ }
+
+ // Given that exp is an integer, here are the
+ // ways that pow can return a negative value:
+ //
+ // pow(-x, exp) --> negative if exp is odd and x is negative.
+ // pow(-0, exp) --> -inf if exp is negative odd.
+ // pow(-0, exp) --> -0 if exp is positive odd.
+ // pow(-inf, exp) --> -0 if exp is negative odd.
+ // pow(-inf, exp) --> -inf if exp is positive odd.
+ KnownFPClass KnownSrc;
+ computeKnownFPClass(II->getArgOperand(0), DemandedElts, fcNegative,
+ KnownSrc, Depth + 1, Q, TLI);
+ if (KnownSrc.isKnownNever(fcNegative))
+ Known.knownNot(fcNegative);
+ break;
+ }
case Intrinsic::arithmetic_fence: {
computeKnownFPClass(II->getArgOperand(0), DemandedElts,
InterestedClasses, Known, Depth + 1, Q, TLI);