summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerguei Katkov <serguei.i.katkov@intel.com>2015-08-07 13:26:14 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-07 13:26:14 +0000
commita1620b7f44ab2ebc800ce29e6378a3aa7776022e (patch)
tree0c133429186d7d9f796efa2d883941a8130246e0
parentc01d9e9e9b9d5140b366943735fe1e0a18ab4416 (diff)
parentf2ea71cdb3ee4f5198bc0298aa8be1f9e945ee1c (diff)
downloadandroid_art-a1620b7f44ab2ebc800ce29e6378a3aa7776022e.tar.gz
android_art-a1620b7f44ab2ebc800ce29e6378a3aa7776022e.tar.bz2
android_art-a1620b7f44ab2ebc800ce29e6378a3aa7776022e.zip
am f2ea71cd: ART: Fix the simplifier for add/sub
* commit 'f2ea71cdb3ee4f5198bc0298aa8be1f9e945ee1c': ART: Fix the simplifier for add/sub
-rw-r--r--compiler/optimizing/instruction_simplifier.cc24
-rw-r--r--test/474-fp-sub-neg/expected.txt4
-rw-r--r--test/474-fp-sub-neg/info.txt6
-rw-r--r--test/474-fp-sub-neg/src/Main.java4
4 files changed, 30 insertions, 8 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 0ca676a85e..9ab9398ca1 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -314,9 +314,14 @@ void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) {
// ADD dst, src, 0
// with
// src
- instruction->ReplaceWith(input_other);
- instruction->GetBlock()->RemoveInstruction(instruction);
- return;
+ // Note that we cannot optimize `x + 0.0` to `x` for floating-point. When
+ // `x` is `-0.0`, the former expression yields `0.0`, while the later
+ // yields `-0.0`.
+ if (Primitive::IsIntegralType(instruction->GetType())) {
+ instruction->ReplaceWith(input_other);
+ instruction->GetBlock()->RemoveInstruction(instruction);
+ return;
+ }
}
HInstruction* left = instruction->GetLeft();
@@ -606,21 +611,24 @@ void InstructionSimplifierVisitor::VisitSub(HSub* instruction) {
HConstant* input_cst = instruction->GetConstantRight();
HInstruction* input_other = instruction->GetLeastConstantLeft();
+ Primitive::Type type = instruction->GetType();
+ if (Primitive::IsFloatingPointType(type)) {
+ return;
+ }
+
if ((input_cst != nullptr) && input_cst->IsZero()) {
// Replace code looking like
// SUB dst, src, 0
// with
// src
+ // Note that we cannot optimize `x - 0.0` to `x` for floating-point. When
+ // `x` is `-0.0`, the former expression yields `0.0`, while the later
+ // yields `-0.0`.
instruction->ReplaceWith(input_other);
instruction->GetBlock()->RemoveInstruction(instruction);
return;
}
- Primitive::Type type = instruction->GetType();
- if (!Primitive::IsIntegralType(type)) {
- return;
- }
-
HBasicBlock* block = instruction->GetBlock();
ArenaAllocator* allocator = GetGraph()->GetArena();
diff --git a/test/474-fp-sub-neg/expected.txt b/test/474-fp-sub-neg/expected.txt
index e6ffe0d430..1c15abba3d 100644
--- a/test/474-fp-sub-neg/expected.txt
+++ b/test/474-fp-sub-neg/expected.txt
@@ -1,2 +1,6 @@
-0.0
+0.0
+0.0
-0.0
+0.0
+0.0
diff --git a/test/474-fp-sub-neg/info.txt b/test/474-fp-sub-neg/info.txt
index eced93fef5..82effdb45e 100644
--- a/test/474-fp-sub-neg/info.txt
+++ b/test/474-fp-sub-neg/info.txt
@@ -1,5 +1,11 @@
Regression check for optimizing simplify instruction pass.
+
A pair (sub, neg) should not be transforemd to (sub) for
fp calculation because we can lose the sign of zero for
the following expression:
- ( A - B ) != B - A ; if B == A
+
+Addition or subtraction with fp zero should not be eliminated
+because:
+ -0.0 + 0.0 = 0.0
+ -0.0 - -0.0 = 0.0
diff --git a/test/474-fp-sub-neg/src/Main.java b/test/474-fp-sub-neg/src/Main.java
index e6bce6793f..c190e8e40b 100644
--- a/test/474-fp-sub-neg/src/Main.java
+++ b/test/474-fp-sub-neg/src/Main.java
@@ -24,6 +24,8 @@ public class Main {
}
System.out.println(f);
+ System.out.println(f + 0f);
+ System.out.println(f - (-0f));
}
public static void doubleTest() {
@@ -35,6 +37,8 @@ public class Main {
}
System.out.println(d);
+ System.out.println(d + 0f);
+ System.out.println(d - (-0f));
}
public static void main(String[] args) {