OSDN Git Service

Fix HDoubleConstant::IsZero and HFloatConstant::IsZero.
authorNicolas Geoffray <ngeoffray@google.com>
Tue, 15 Mar 2016 16:23:04 +0000 (16:23 +0000)
committerNicolas Geoffray <ngeoffray@google.com>
Tue, 15 Mar 2016 16:23:04 +0000 (16:23 +0000)
bug:27639313
Change-Id: I2f30a65a07662dfce0a6d6f4ed356a8a0b3dcdef

compiler/optimizing/nodes.h
test/583-checker-zero/expected.txt [new file with mode: 0644]
test/583-checker-zero/info.txt [new file with mode: 0644]
test/583-checker-zero/src/Main.java [new file with mode: 0644]

index 1bb5f5d..4a4f193 100644 (file)
@@ -2543,7 +2543,7 @@ class HFloatConstant : public HConstant {
     return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f));
   }
   bool IsZero() const OVERRIDE {
-    return value_ == 0.0f;
+    return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(0.0f);
   }
   bool IsOne() const OVERRIDE {
     return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f);
@@ -2585,7 +2585,7 @@ class HDoubleConstant : public HConstant {
     return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0));
   }
   bool IsZero() const OVERRIDE {
-    return value_ == 0.0;
+    return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((0.0));
   }
   bool IsOne() const OVERRIDE {
     return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0);
diff --git a/test/583-checker-zero/expected.txt b/test/583-checker-zero/expected.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/583-checker-zero/info.txt b/test/583-checker-zero/info.txt
new file mode 100644 (file)
index 0000000..8ec5d48
--- /dev/null
@@ -0,0 +1,2 @@
+Regression test for optimizing that used to think 0.0 has the same bits
+as -0.0.
diff --git a/test/583-checker-zero/src/Main.java b/test/583-checker-zero/src/Main.java
new file mode 100644 (file)
index 0000000..39369fc
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+  /// CHECK-START: void Main.main(String[]) inliner (after)
+  /// CHECK: HInstanceFieldSet
+  public static void main(String[] args) {
+    if (new Float(0f).equals(new Float(-0f))) {
+      throw new Error("Expected not equal");
+    }
+  }
+}