Incorrect transformation of (sub,neg) to (sub) for fp
A pair (sub,neg) should not be transformed to (sub) for
floating point operations, otherwise we can lose the sign of
zero for instructions like this:
- (A - B) != B - A if B == A
Change-Id: I4d612612d4dc0a067fac5721ad206f74168bcd36
Signed-off-by: Serguei Katkov <serguei.i.katkov@intel.com>
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index afbc490..180bdc9 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -424,7 +424,8 @@
return;
}
- if (input->IsSub() && input->HasOnlyOneNonEnvironmentUse()) {
+ if (input->IsSub() && input->HasOnlyOneNonEnvironmentUse() &&
+ !Primitive::IsFloatingPointType(input->GetType())) {
// Replace code looking like
// SUB tmp, a, b
// NEG dst, tmp
@@ -435,6 +436,7 @@
// worse code. In particular, we do not want the live ranges of `a` and `b`
// to be extended if we are not sure the initial 'SUB' instruction can be
// removed.
+ // We do not perform optimization for fp because we could lose the sign of zero.
HSub* sub = input->AsSub();
HSub* new_sub =
new (GetGraph()->GetArena()) HSub(instruction->GetType(), sub->GetRight(), sub->GetLeft());