| 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/compiler/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/compiler/diamond.h" | 10 #include "src/compiler/diamond.h" |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 Int32BinopMatcher m(node); | 825 Int32BinopMatcher m(node); |
| 826 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 | 826 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 |
| 827 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x | 827 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x |
| 828 if (m.left().IsComparison() && m.right().Is(1)) { // CMP & 1 => CMP | 828 if (m.left().IsComparison() && m.right().Is(1)) { // CMP & 1 => CMP |
| 829 return Replace(m.left().node()); | 829 return Replace(m.left().node()); |
| 830 } | 830 } |
| 831 if (m.IsFoldable()) { // K & K => K | 831 if (m.IsFoldable()) { // K & K => K |
| 832 return ReplaceInt32(m.left().Value() & m.right().Value()); | 832 return ReplaceInt32(m.left().Value() & m.right().Value()); |
| 833 } | 833 } |
| 834 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x | 834 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x |
| 835 if (m.right().HasValue()) { |
| 836 int32_t const mask = m.right().Value(); |
| 837 Type* left_type = NodeProperties::GetBounds(m.left().node()).upper; |
| 838 if (left_type->IsRange() && left_type->Min() >= kMinInt && |
| 839 left_type->Max() <= kMaxInt) { |
| 840 // If the left hand side known one bits and unknown bits are preserve by |
| 841 // the mask then the bitwise-and operation can be eliminated. |
| 842 uint32_t left_min = left_type->Min(), left_max = left_type->Max(); |
| 843 uint32_t changes = left_min ^ left_max; |
| 844 unsigned known_count = base::bits::CountLeadingZeros32(changes); |
| 845 uint32_t known_mask = known_count > 0 ? -1 << (32 - known_count) : 0; |
| 846 uint32_t known_ones = left_min & known_mask; |
| 847 if ((known_ones & mask) == known_ones && |
| 848 (~known_mask & mask) == ~known_mask) { // x & K => x |
| 849 return Replace(m.left().node()); |
| 850 } |
| 851 } |
| 852 } |
| 835 if (m.left().IsWord32And() && m.right().HasValue()) { | 853 if (m.left().IsWord32And() && m.right().HasValue()) { |
| 836 Int32BinopMatcher mleft(m.left().node()); | 854 Int32BinopMatcher mleft(m.left().node()); |
| 837 if (mleft.right().HasValue()) { // (x & K) & K => x & K | 855 if (mleft.right().HasValue()) { // (x & K) & K => x & K |
| 838 node->ReplaceInput(0, mleft.left().node()); | 856 node->ReplaceInput(0, mleft.left().node()); |
| 839 node->ReplaceInput( | 857 node->ReplaceInput( |
| 840 1, Int32Constant(m.right().Value() & mleft.right().Value())); | 858 1, Int32Constant(m.right().Value() & mleft.right().Value())); |
| 841 Reduction const reduction = ReduceWord32And(node); | 859 Reduction const reduction = ReduceWord32And(node); |
| 842 return reduction.Changed() ? reduction : Changed(node); | 860 return reduction.Changed() ? reduction : Changed(node); |
| 843 } | 861 } |
| 844 } | 862 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1031 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 1014 return jsgraph()->machine(); | 1032 return jsgraph()->machine(); |
| 1015 } | 1033 } |
| 1016 | 1034 |
| 1017 | 1035 |
| 1018 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1036 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 1019 | 1037 |
| 1020 } // namespace compiler | 1038 } // namespace compiler |
| 1021 } // namespace internal | 1039 } // namespace internal |
| 1022 } // namespace v8 | 1040 } // namespace v8 |
| OLD | NEW |