Extend JSBuiltinReducer to cover Math.fround as well.

R=bmeurer@chromium.org
TEST=compiler-unittests/JSBuiltinReducerTest.MathFround

Review URL: https://codereview.chromium.org/594183004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4c327306
......@@ -323,7 +323,6 @@ class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder {
OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
DCHECK(isolate()->use_crankshaft());
DCHECK(info()->IsOptimizing());
DCHECK(!info()->IsCompilingForDebugging());
......
......@@ -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)
......
......@@ -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);
......
......@@ -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);
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0));
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -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;
}
......
......@@ -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_;
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --turbo-asm
function Module(stdlib) {
"use asm";
var fround = stdlib.Math.fround;
// f: double -> float
function f(a) {
a = +a;
return fround(a);
}
return { f: f };
}
var f = Module({ Math: Math }).f;
assertTrue(isNaN(f(NaN)));
assertTrue(isNaN(f(undefined)));
assertTrue(isNaN(f(function() {})));
assertEquals("Infinity", String(1/f(0)));
assertEquals("-Infinity", String(1/f(-0)));
assertEquals("Infinity", String(f(Infinity)));
assertEquals("-Infinity", String(f(-Infinity)));
assertEquals("Infinity", String(f(1E200)));
assertEquals("-Infinity", String(f(-1E200)));
assertEquals("Infinity", String(1/f(1E-300)));
assertEquals("-Infinity", String(1/f(-1E-300)));
assertEquals(0, f(0));
assertEquals(1, f(1));
assertEquals(1.5, f(1.5));
assertEquals(1.3370000123977661, f(1.337));
assertEquals(-4.300000190734863, f(-4.3));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment