Have CannotBeNegativeZero() be aware of the nsz fast-math flag
authorMichael Ilseman <milseman@apple.com>
Thu, 6 Dec 2012 00:07:09 +0000 (00:07 +0000)
committerMichael Ilseman <milseman@apple.com>
Thu, 6 Dec 2012 00:07:09 +0000 (00:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169452 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp

index 47b1db6425b89df2d1b198cdc8e8611f43d8888d..eee231df8c9b48ea2c81c55ee0ccd2bb08d552c4 100644 (file)
@@ -1312,7 +1312,12 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
 
   const Operator *I = dyn_cast<Operator>(V);
   if (I == 0) return false;
-  
+
+  // Check if the nsz fast-math flag is set
+  if (const FPMathOperator *FPO = dyn_cast<FPMathOperator>(I))
+    if (FPO->hasNoSignedZeros())
+      return true;
+
   // (add x, 0.0) is guaranteed to return +0.0, not -0.0.
   if (I->getOpcode() == Instruction::FAdd &&
       isa<ConstantFP>(I->getOperand(1)) &&