Reviewers: jarin,

Description:
[turbofan] Improve test coverage for ToBit representation changes.

TEST=cctest/test-representation-change
[email protected]

Please review this at https://codereview.chromium.org/843663002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+48, -8 lines):
  M src/compiler/representation-change.h
  M test/cctest/compiler/test-representation-change.cc


Index: src/compiler/representation-change.h
diff --git a/src/compiler/representation-change.h b/src/compiler/representation-change.h index 8720afdde3ff8938e46ed2f1ab19a647e591e3da..32bdee3dd0dc469e439bd2aa51ac96e526d2dbd0 100644
--- a/src/compiler/representation-change.h
+++ b/src/compiler/representation-change.h
@@ -298,10 +298,8 @@ class RepresentationChanger {
       }
       case IrOpcode::kNumberConstant: {
         double value = OpParameter<double>(node);
-        if (std::isnan(value) || value == 0.0) {
-          return jsgraph()->Int32Constant(0);
-        }
-        return jsgraph()->Int32Constant(1);
+ if (value == 0.0 || value != value) return jsgraph()->Int32Constant(0);
+        return jsgraph()->Int32Constant(1);  // value != +0.0, -0.0, NaN
       }
       case IrOpcode::kHeapConstant: {
Handle<Object> handle = OpParameter<Unique<Object>
(node).handle();
Index: test/cctest/compiler/test-representation-change.cc
diff --git a/test/cctest/compiler/test-representation-change.cc b/test/cctest/compiler/test-representation-change.cc index 2dc30294a29cd6223cde2de2894f174c16d9667b..31424582d5f2eaaf0968dca28e356185852bf364 100644
--- a/test/cctest/compiler/test-representation-change.cc
+++ b/test/cctest/compiler/test-representation-change.cc
@@ -98,16 +98,17 @@ class RepresentationChangerTester : public HandleAndZoneScope,
     CHECK_EQ(n, c);
   }
 };
-}
-}
-}  // namespace v8::internal::compiler
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8


static const MachineType all_reps[] = {kRepBit, kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged};


-TEST(BoolToBit_constant) {
+TEST(ToBit_constant) {
   RepresentationChangerTester r;

   Node* true_node = r.jsgraph()->TrueConstant();
@@ -119,6 +120,47 @@ TEST(BoolToBit_constant) {
   Node* false_bit =
       r.changer()->GetRepresentationFor(false_node, kRepTagged, kRepBit);
   r.CheckInt32Constant(false_bit, 0);
+
+  Node* nan_node = r.jsgraph()->NaNConstant();
+  Node* nan_bit =
+      r.changer()->GetRepresentationFor(nan_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(nan_bit, 0);
+
+  Node* zero_node = r.jsgraph()->ZeroConstant();
+  Node* zero_bit =
+      r.changer()->GetRepresentationFor(zero_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(zero_bit, 0);
+
+  Node* minus_zero_node = r.jsgraph()->Constant(-0.0);
+  Node* minus_zero_bit =
+ r.changer()->GetRepresentationFor(minus_zero_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(minus_zero_bit, 0);
+
+  Node* one_node = r.jsgraph()->OneConstant();
+  Node* one_bit =
+      r.changer()->GetRepresentationFor(one_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(one_bit, 1);
+
+  Node* pi_node = r.jsgraph()->Constant(3.1415926535897932);
+  Node* pi_bit =
+      r.changer()->GetRepresentationFor(pi_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(pi_bit, 1);
+
+  Node* infinity_node = r.jsgraph()->Constant(V8_INFINITY);
+  Node* infinity_bit =
+ r.changer()->GetRepresentationFor(infinity_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(infinity_bit, 1);
+
+  Node* minus_infinity_node = r.jsgraph()->Constant(-V8_INFINITY);
+  Node* minus_infinity_bit = r.changer()->GetRepresentationFor(
+      minus_infinity_node, kRepTagged, kRepBit);
+  r.CheckInt32Constant(minus_infinity_bit, 1);
+
+  for (int i = 0; i <= 1; ++i) {
+    Node* node = r.jsgraph()->Int32Constant(i);
+ Node* bit = r.changer()->GetRepresentationFor(node, kRepWord32, kRepBit);
+    r.CheckInt32Constant(bit, i == 0 ? 0 : 1);
+  }
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to