ART: Fix the simplifier for NEGATE add/sub
Instruction simplifier for negate add/sub should not proceed
with floats because that might cause the incorrect behavior
with signed zero.
Change-Id: I4970694a2b265a3577cde34fee9cd3a437358c0f
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index df6e550..0ac26de 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -132,6 +132,12 @@
// with
// ADD tmp, a, b
// NEG dst, tmp
+ // Note that we cannot optimize `(-a) + (-b)` to `-(a + b)` for floating-point.
+ // When `a` is `-0.0` and `b` is `0.0`, the former expression yields `0.0`,
+ // while the later yields `-0.0`.
+ if (!Primitive::IsIntegralType(binop->GetType())) {
+ return false;
+ }
binop->ReplaceInput(left_neg->GetInput(), 0);
binop->ReplaceInput(right_neg->GetInput(), 1);
left_neg->GetBlock()->RemoveInstruction(left_neg);