| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/bits.h" | 5 #include "src/base/bits.h" |
| 6 #include "src/base/division-by-constant.h" | 6 #include "src/base/division-by-constant.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/machine-operator-reducer.h" | 8 #include "src/compiler/machine-operator-reducer.h" |
| 9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
| 10 #include "src/conversions-inl.h" | 10 #include "src/conversions-inl.h" |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 p0, Type::Intersect(p0_range, Type::Number(), graph()->zone())); | 1672 p0, Type::Intersect(p0_range, Type::Number(), graph()->zone())); |
| 1673 | 1673 |
| 1674 Node* t0 = graph()->NewNode(machine()->RoundInt64ToFloat64(), p0); | 1674 Node* t0 = graph()->NewNode(machine()->RoundInt64ToFloat64(), p0); |
| 1675 Node* t1 = graph()->NewNode( | 1675 Node* t1 = graph()->NewNode( |
| 1676 machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript), t0); | 1676 machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript), t0); |
| 1677 | 1677 |
| 1678 Reduction r = Reduce(t1); | 1678 Reduction r = Reduce(t1); |
| 1679 ASSERT_TRUE(!r.Changed()); | 1679 ASSERT_TRUE(!r.Changed()); |
| 1680 } | 1680 } |
| 1681 | 1681 |
| 1682 | |
| 1683 TEST_F(MachineOperatorReducerTest, Div52OfMul52) { | |
| 1684 // This reduction applies only to 64bit arch | |
| 1685 if (!machine()->Is64()) return; | |
| 1686 | |
| 1687 Node* p0 = Parameter(0); | |
| 1688 Node* p1 = Parameter(1); | |
| 1689 Node* t0 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p0); | |
| 1690 Node* t1 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p1); | |
| 1691 | |
| 1692 int64_t max = 0xFFFFFFFFFFFFFULL; | |
| 1693 Type* mul_range = Type::Range(0x0, max, graph()->zone()); | |
| 1694 Node* mul = graph()->NewNode(machine()->Float64Mul(), t0, t1); | |
| 1695 NodeProperties::SetType( | |
| 1696 mul, Type::Intersect(mul_range, Type::Number(), graph()->zone())); | |
| 1697 | |
| 1698 Node* mul_replacement; | |
| 1699 auto mul_matcher = IsInt64Mul(p0, p1); | |
| 1700 | |
| 1701 Reduction r = Reduce(mul); | |
| 1702 ASSERT_TRUE(r.Changed()); | |
| 1703 mul_replacement = r.replacement(); | |
| 1704 EXPECT_THAT(mul_replacement, IsRoundInt64ToFloat64(mul_matcher)); | |
| 1705 | |
| 1706 Node* power = Float64Constant(0x4000000); | |
| 1707 Node* div = graph()->NewNode(machine()->Float64Div(), mul_replacement, power); | |
| 1708 | |
| 1709 auto shr_matcher = IsWord64Shr(mul_matcher, IsInt64Constant(26)); | |
| 1710 | |
| 1711 r = Reduce(div); | |
| 1712 ASSERT_TRUE(r.Changed()); | |
| 1713 EXPECT_THAT(r.replacement(), IsRoundInt64ToFloat64(shr_matcher)); | |
| 1714 | |
| 1715 // It should set `shr` range for reduction of RoundInt64ToFloat64 | |
| 1716 Type* type = NodeProperties::GetType(r.replacement()->InputAt(0)); | |
| 1717 Type::RangeType* range = type->GetRange(); | |
| 1718 ASSERT_TRUE(range != nullptr && range->Min() == 0 && | |
| 1719 range->Max() == max / 0x4000000); | |
| 1720 } | |
| 1721 | |
| 1722 | |
| 1723 TEST_F(MachineOperatorReducerTest, Div52OfOverflowingValue) { | |
| 1724 // This reduction applies only to 64bit arch | |
| 1725 if (!machine()->Is64()) return; | |
| 1726 | |
| 1727 Node* p0 = Parameter(0); | |
| 1728 Node* t0 = graph()->NewNode(machine()->RoundInt64ToFloat64(), p0); | |
| 1729 | |
| 1730 int64_t max = 0xFFFFFFFFFFFFFFULL; | |
| 1731 Type* p0_range = Type::Range(0x0, max, graph()->zone()); | |
| 1732 NodeProperties::SetType( | |
| 1733 p0, Type::Intersect(p0_range, Type::Number(), graph()->zone())); | |
| 1734 | |
| 1735 Node* power = Float64Constant(0x4000000); | |
| 1736 Node* div = graph()->NewNode(machine()->Float64Div(), t0, power); | |
| 1737 | |
| 1738 Reduction r = Reduce(div); | |
| 1739 ASSERT_TRUE(!r.Changed()); | |
| 1740 } | |
| 1741 | |
| 1742 } // namespace compiler | 1682 } // namespace compiler |
| 1743 } // namespace internal | 1683 } // namespace internal |
| 1744 } // namespace v8 | 1684 } // namespace v8 |
| OLD | NEW |