[cfe-commits] r107019 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/exprs.c

Chris Lattner sabre at nondot.org
Mon Jun 28 10:12:37 PDT 2010


Author: lattner
Date: Mon Jun 28 12:12:37 2010
New Revision: 107019

URL: http://llvm.org/viewvc/llvm-project?rev=107019&view=rev
Log:
Fix UnitTests/2004-02-02-NegativeZero.c, which regressed when
I broke negate of FP values.


Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/exprs.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=107019&r1=107018&r2=107019&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Jun 28 12:12:37 2010
@@ -1224,8 +1224,12 @@
   TestAndClearIgnoreResultAssign();
   // Emit unary minus with EmitSub so we handle overflow cases etc.
   BinOpInfo BinOp;
-  BinOp.RHS = Visit(E->getSubExpr());;
-  BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
+  BinOp.RHS = Visit(E->getSubExpr());
+  
+  if (BinOp.RHS->getType()->isFPOrFPVectorTy())
+    BinOp.LHS = llvm::ConstantFP::getZeroValueForNegation(BinOp.RHS->getType());
+  else 
+    BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
   BinOp.Ty = E->getType();
   BinOp.Opcode = BinaryOperator::Sub;
   BinOp.E = E;

Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=107019&r1=107018&r2=107019&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Mon Jun 28 12:12:37 2010
@@ -137,3 +137,10 @@
   // CHECK: ret i32 1
   return 1||1;
 }
+
+// Make sure negate of fp uses -0.0 for proper -0 handling.
+double f13(double X) {
+  // CHECK: define double @f13
+  // CHECK: fsub double -0.000000e+00, %tmp
+  return -X;
+}





More information about the cfe-commits mailing list