c3cbcdefc7be70234035d507228c593cd049a638
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / common-operator-reducer.cc
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
3 // found in the LICENSE file.
4
5 #include "src/compiler/common-operator-reducer.h"
6
7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/node.h"
9
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13
14 Reduction CommonOperatorReducer::Reduce(Node* node) {
15   switch (node->opcode()) {
16     case IrOpcode::kEffectPhi:
17     case IrOpcode::kPhi: {
18       int const input_count = node->InputCount();
19       if (input_count > 1) {
20         Node* const replacement = node->InputAt(0);
21         for (int i = 1; i < input_count - 1; ++i) {
22           if (node->InputAt(i) != replacement) return NoChange();
23         }
24         return Replace(replacement);
25       }
26       break;
27     }
28     case IrOpcode::kSelect: {
29       if (node->InputAt(1) == node->InputAt(2)) {
30         return Replace(node->InputAt(1));
31       }
32       break;
33     }
34     default:
35       break;
36   }
37   return NoChange();
38 }
39
40 }  // namespace compiler
41 }  // namespace internal
42 }  // namespace v8