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)
llvm-svn: 169452

llvm/lib/Analysis/ValueTracking.cpp

index 47b1db6..eee231d 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)) &&