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/load-elimination.h" | 5 #include "src/compiler/load-elimination.h" |
6 | 6 |
| 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/graph.h" |
7 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/simplified-operator.h" | 10 #include "src/compiler/simplified-operator.h" |
| 11 #include "src/types.h" |
9 | 12 |
10 namespace v8 { | 13 namespace v8 { |
11 namespace internal { | 14 namespace internal { |
12 namespace compiler { | 15 namespace compiler { |
13 | 16 |
14 LoadElimination::~LoadElimination() {} | 17 LoadElimination::~LoadElimination() {} |
15 | 18 |
16 | |
17 Reduction LoadElimination::Reduce(Node* node) { | 19 Reduction LoadElimination::Reduce(Node* node) { |
18 switch (node->opcode()) { | 20 switch (node->opcode()) { |
19 case IrOpcode::kLoadField: | 21 case IrOpcode::kLoadField: |
20 return ReduceLoadField(node); | 22 return ReduceLoadField(node); |
21 default: | 23 default: |
22 break; | 24 break; |
23 } | 25 } |
24 return NoChange(); | 26 return NoChange(); |
25 } | 27 } |
26 | 28 |
27 | |
28 Reduction LoadElimination::ReduceLoadField(Node* node) { | 29 Reduction LoadElimination::ReduceLoadField(Node* node) { |
29 DCHECK_EQ(IrOpcode::kLoadField, node->opcode()); | 30 DCHECK_EQ(IrOpcode::kLoadField, node->opcode()); |
30 FieldAccess const access = FieldAccessOf(node->op()); | 31 FieldAccess const access = FieldAccessOf(node->op()); |
31 Node* object = NodeProperties::GetValueInput(node, 0); | 32 Node* object = NodeProperties::GetValueInput(node, 0); |
32 for (Node* effect = NodeProperties::GetEffectInput(node);; | 33 for (Node* effect = NodeProperties::GetEffectInput(node);; |
33 effect = NodeProperties::GetEffectInput(effect)) { | 34 effect = NodeProperties::GetEffectInput(effect)) { |
34 switch (effect->opcode()) { | 35 switch (effect->opcode()) { |
35 case IrOpcode::kLoadField: { | 36 case IrOpcode::kLoadField: { |
36 if (object == NodeProperties::GetValueInput(effect, 0) && | 37 if (object == NodeProperties::GetValueInput(effect, 0) && |
37 access == FieldAccessOf(effect->op())) { | 38 access == FieldAccessOf(effect->op())) { |
38 Node* const value = effect; | 39 Node* const value = effect; |
39 ReplaceWithValue(node, value); | 40 ReplaceWithValue(node, value); |
40 return Replace(value); | 41 return Replace(value); |
41 } | 42 } |
42 break; | 43 break; |
43 } | 44 } |
44 case IrOpcode::kStoreField: { | 45 case IrOpcode::kStoreField: { |
45 if (access == FieldAccessOf(effect->op())) { | 46 if (access == FieldAccessOf(effect->op())) { |
46 if (object == NodeProperties::GetValueInput(effect, 0)) { | 47 if (object == NodeProperties::GetValueInput(effect, 0)) { |
47 Node* const value = NodeProperties::GetValueInput(effect, 1); | 48 Node* const value = NodeProperties::GetValueInput(effect, 1); |
48 ReplaceWithValue(node, value); | 49 Type* stored_value_type = NodeProperties::GetType(value); |
49 return Replace(value); | 50 Type* load_type = NodeProperties::GetType(node); |
| 51 // Make sure the replacement's type is a subtype of the node's |
| 52 // type. Otherwise we could confuse optimizations that were |
| 53 // based on the original type. |
| 54 if (stored_value_type->Is(load_type)) { |
| 55 ReplaceWithValue(node, value); |
| 56 return Replace(value); |
| 57 } else { |
| 58 Node* renamed = graph()->NewNode( |
| 59 common()->Guard(Type::Intersect(stored_value_type, load_type, |
| 60 graph()->zone())), |
| 61 value, NodeProperties::GetControlInput(node)); |
| 62 ReplaceWithValue(node, renamed); |
| 63 return Replace(renamed); |
| 64 } |
50 } | 65 } |
51 // TODO(turbofan): Alias analysis to the rescue? | 66 // TODO(turbofan): Alias analysis to the rescue? |
52 return NoChange(); | 67 return NoChange(); |
53 } | 68 } |
54 break; | 69 break; |
55 } | 70 } |
56 case IrOpcode::kBeginRegion: | 71 case IrOpcode::kBeginRegion: |
57 case IrOpcode::kStoreBuffer: | 72 case IrOpcode::kStoreBuffer: |
58 case IrOpcode::kStoreElement: { | 73 case IrOpcode::kStoreElement: { |
59 // These can never interfere with field loads. | 74 // These can never interfere with field loads. |
(...skipping 20 matching lines...) Expand all Loading... |
80 } | 95 } |
81 } | 96 } |
82 } | 97 } |
83 UNREACHABLE(); | 98 UNREACHABLE(); |
84 return NoChange(); | 99 return NoChange(); |
85 } | 100 } |
86 | 101 |
87 } // namespace compiler | 102 } // namespace compiler |
88 } // namespace internal | 103 } // namespace internal |
89 } // namespace v8 | 104 } // namespace v8 |
OLD | NEW |