aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-06-28 17:12:37 +0000
committerChris Lattner <sabre@nondot.org>2010-06-28 17:12:37 +0000
commit4ac0d83090c750bd8ab2c4fc91a6a44c32884cb3 (patch)
tree32eccb57b80a52ae89172d0ed3903572819c315f
parent1ea9c3d2855de75ee89768696af3eda6aa3de723 (diff)
Fix UnitTests/2004-02-02-NegativeZero.c, which regressed when
I broke negate of FP values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107019 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprScalar.cpp8
-rw-r--r--test/CodeGen/exprs.c7
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index d0d89c66a4..e2b4d2dd15 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1224,8 +1224,12 @@ Value *ScalarExprEmitter::VisitUnaryMinus(const UnaryOperator *E) {
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;
diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c
index b3cf9133bd..f7b02bc8a0 100644
--- a/test/CodeGen/exprs.c
+++ b/test/CodeGen/exprs.c
@@ -137,3 +137,10 @@ int f12() {
// 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;
+}