aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-09-29 15:51:05 +0200
committerNikita Popov <npopov@redhat.com>2022-09-29 17:07:48 +0200
commitaa25c92f33e42be16446b356ba82a10e7043572d (patch)
treead6e2fcfbe5a5cea668dd39d68eb70f5a72457fa /llvm/lib/Analysis/ValueTracking.cpp
parent8b38a2c0a55a9140115a91959326918d99bea435 (diff)
downloadllvm-aa25c92f33e42be16446b356ba82a10e7043572d.zip
llvm-aa25c92f33e42be16446b356ba82a10e7043572d.tar.gz
llvm-aa25c92f33e42be16446b356ba82a10e7043572d.tar.bz2
[ValueTracking] Fix CannotBeOrderedLessThanZero() for fdiv (PR58046)
When checking the RHS of fdiv, we should set the SignBitOnly flag, because a negative zero can become -Inf, which is ordered less than zero. Fixes https://github.com/llvm/llvm-project/issues/58046. Differential Revision: https://reviews.llvm.org/D134876
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 3826b47..ddc96f7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3629,14 +3629,23 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
// Unsigned integers are always nonnegative.
case Instruction::UIToFP:
return true;
- case Instruction::FMul:
case Instruction::FDiv:
- // X * X is always non-negative or a NaN.
// X / X is always exactly 1.0 or a NaN.
if (I->getOperand(0) == I->getOperand(1) &&
(!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()))
return true;
+ // Set SignBitOnly for RHS, because X / -0.0 is -Inf (or NaN).
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
+ Depth + 1) &&
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI,
+ /*SignBitOnly*/ true, Depth + 1);
+ case Instruction::FMul:
+ // X * X is always non-negative or a NaN.
+ if (I->getOperand(0) == I->getOperand(1) &&
+ (!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()))
+ return true;
+
[[fallthrough]];
case Instruction::FAdd:
case Instruction::FRem: