Reviewers: Benedikt Meurer,

Description:
Extend JSBuiltinReducer to cover Math.fround as well.

[email protected]
TEST=compiler-unittests/JSBuiltinReducerTest.MathFround

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+44, -0 lines):
  M src/compiler/graph-unittest.h
  M src/compiler/graph-unittest.cc
  M src/compiler/js-builtin-reducer.h
  M src/compiler/js-builtin-reducer.cc
  M src/compiler/js-builtin-reducer-unittest.cc


Index: src/compiler/graph-unittest.cc
diff --git a/src/compiler/graph-unittest.cc b/src/compiler/graph-unittest.cc
index 75e70cb05d84c582a9ae782431c929a58eb3e4ad..0071b81e25df063d024de70551f35aa475763039 100644
--- a/src/compiler/graph-unittest.cc
+++ b/src/compiler/graph-unittest.cc
@@ -769,6 +769,7 @@ IS_UNOP_MATCHER(ChangeInt32ToFloat64)
 IS_UNOP_MATCHER(ChangeInt32ToInt64)
 IS_UNOP_MATCHER(ChangeUint32ToFloat64)
 IS_UNOP_MATCHER(ChangeUint32ToUint64)
+IS_UNOP_MATCHER(TruncateFloat64ToFloat32)
 IS_UNOP_MATCHER(TruncateFloat64ToInt32)
 IS_UNOP_MATCHER(TruncateInt64ToInt32)
 IS_UNOP_MATCHER(Float64Sqrt)
Index: src/compiler/graph-unittest.h
diff --git a/src/compiler/graph-unittest.h b/src/compiler/graph-unittest.h
index 1dc9c3dae72b215edf9f65cbf9d3024fbf15f6c6..04d4af07c726c8c37735562c70432f8aed422548 100644
--- a/src/compiler/graph-unittest.h
+++ b/src/compiler/graph-unittest.h
@@ -129,6 +129,7 @@ Matcher<Node*> IsChangeInt32ToFloat64(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsChangeInt32ToInt64(const Matcher<Node*>& input_matcher);
Matcher<Node*> IsChangeUint32ToFloat64(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsChangeUint32ToUint64(const Matcher<Node*>& input_matcher);
+Matcher<Node*> IsTruncateFloat64ToFloat32(const Matcher<Node*>& input_matcher); Matcher<Node*> IsTruncateFloat64ToInt32(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsTruncateInt64ToInt32(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsFloat64Sqrt(const Matcher<Node*>& input_matcher);
Index: src/compiler/js-builtin-reducer-unittest.cc
diff --git a/src/compiler/js-builtin-reducer-unittest.cc b/src/compiler/js-builtin-reducer-unittest.cc index 51561d0732665f15e067c6d3c7b29ee742621ffc..72df8351ed9a96d00b1f12b16466cad785068fa6 100644
--- a/src/compiler/js-builtin-reducer-unittest.cc
+++ b/src/compiler/js-builtin-reducer-unittest.cc
@@ -172,6 +172,32 @@ TEST_F(JSBuiltinReducerTest, MathImul) {
   }
 }

+
+// -----------------------------------------------------------------------------
+// Math.fround
+
+
+TEST_F(JSBuiltinReducerTest, MathFround) {
+  Handle<Object> m =
+      JSObject::GetProperty(isolate()->global_object(),
+ isolate()->factory()->NewStringFromAsciiChecked(
+                                "Math")).ToHandleChecked();
+  Handle<JSFunction> f = Handle<JSFunction>::cast(
+ JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked(
+                                   "fround")).ToHandleChecked());
+
+  TRACED_FOREACH(Type*, t0, kNumberTypes) {
+    Node* p0 = Parameter(t0, 0);
+    Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
+ Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
+                                  fun, UndefinedConstant(), p0);
+    Reduction r = Reduce(call);
+
+    EXPECT_TRUE(r.Changed());
+    EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0));
+  }
+}
+
 }  // namespace compiler
 }  // namespace internal
 }  // namespace v8
Index: src/compiler/js-builtin-reducer.cc
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc index c57ac331defc84611a30732cefea7cb0ae348863..f1aef31619d9273fc43957818473cf394452145b 100644
--- a/src/compiler/js-builtin-reducer.cc
+++ b/src/compiler/js-builtin-reducer.cc
@@ -151,6 +151,19 @@ Reduction JSBuiltinReducer::ReduceMathImul(Node* node) {
 }


+// ES6 draft 08-24-14, section 20.2.2.17.
+Reduction JSBuiltinReducer::ReduceMathFround(Node* node) {
+  JSCallReduction r(node);
+  if (r.InputsMatchOne(Type::Number())) {
+    // Math.fround(a:number) -> TruncateFloat64ToFloat32(a)
+    Node* value =
+        graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left());
+    return Replace(value);
+  }
+  return NoChange();
+}
+
+
 Reduction JSBuiltinReducer::Reduce(Node* node) {
   JSCallReduction r(node);

@@ -163,6 +176,8 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
       return ReplaceWithPureReduction(node, ReduceMathMax(node));
     case kMathImul:
       return ReplaceWithPureReduction(node, ReduceMathImul(node));
+    case kMathFround:
+      return ReplaceWithPureReduction(node, ReduceMathFround(node));
     default:
       break;
   }
Index: src/compiler/js-builtin-reducer.h
diff --git a/src/compiler/js-builtin-reducer.h b/src/compiler/js-builtin-reducer.h index 13927f6b213638b85bf719f402f15ca2fdb31d33..e5a1b8356567d089202c9d05830e269c5fbdcc1f 100644
--- a/src/compiler/js-builtin-reducer.h
+++ b/src/compiler/js-builtin-reducer.h
@@ -33,6 +33,7 @@ class JSBuiltinReducer FINAL : public Reducer {
   Reduction ReduceMathSqrt(Node* node);
   Reduction ReduceMathMax(Node* node);
   Reduction ReduceMathImul(Node* node);
+  Reduction ReduceMathFround(Node* node);

   JSGraph* jsgraph_;
   SimplifiedOperatorBuilder simplified_;


--
--
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