Lines Matching refs:node
13 #include "src/compiler/node-matchers.h"
26 Node* MachineOperatorReducer::Float32Constant(volatile float value) {
31 Node* MachineOperatorReducer::Float64Constant(volatile double value) {
36 Node* MachineOperatorReducer::Int32Constant(int32_t value) {
41 Node* MachineOperatorReducer::Int64Constant(int64_t value) {
46 Node* MachineOperatorReducer::Word32And(Node* lhs, Node* rhs) {
47 Node* const node = graph()->NewNode(machine()->Word32And(), lhs, rhs);
48 Reduction const reduction = ReduceWord32And(node);
49 return reduction.Changed() ? reduction.replacement() : node;
53 Node* MachineOperatorReducer::Word32Sar(Node* lhs, uint32_t rhs) {
59 Node* MachineOperatorReducer::Word32Shr(Node* lhs, uint32_t rhs) {
65 Node* MachineOperatorReducer::Word32Equal(Node* lhs, Node* rhs) {
70 Node* MachineOperatorReducer::Int32Add(Node* lhs, Node* rhs) {
71 Node* const node = graph()->NewNode(machine()->Int32Add(), lhs, rhs);
72 Reduction const reduction = ReduceInt32Add(node);
73 return reduction.Changed() ? reduction.replacement() : node;
77 Node* MachineOperatorReducer::Int32Sub(Node* lhs, Node* rhs) {
78 Node* const node = graph()->NewNode(machine()->Int32Sub(), lhs, rhs);
79 Reduction const reduction = ReduceInt32Sub(node);
80 return reduction.Changed() ? reduction.replacement() : node;
84 Node* MachineOperatorReducer::Int32Mul(Node* lhs, Node* rhs) {
89 Node* MachineOperatorReducer::Int32Div(Node* dividend, int32_t divisor) {
94 Node* quotient = graph()->NewNode(machine()->Int32MulHigh(), dividend,
105 Node* MachineOperatorReducer::Uint32Div(Node* dividend, uint32_t divisor) {
115 Node* quotient = graph()->NewNode(machine()->Uint32MulHigh(), dividend,
130 Reduction MachineOperatorReducer::Reduce(Node* node) {
131 switch (node->opcode()) {
133 return ReduceProjection(ProjectionIndexOf(node->op()), node->InputAt(0));
135 return ReduceWord32And(node);
137 return ReduceWord32Or(node);
139 Int32BinopMatcher m(node);
140 if (m.right().Is(0)) return Replace(m.left().node()); // x ^ 0 => x
146 Int32BinopMatcher mleft(m.left().node());
148 return Replace(mleft.left().node());
154 return ReduceWord32Shl(node);
156 Uint32BinopMatcher m(node);
157 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x
161 return ReduceWord32Shifts(node);
164 return ReduceWord32Sar(node);
166 Int32BinopMatcher m(node);
167 if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x
175 Int32BinopMatcher m(node);
180 Int32BinopMatcher msub(m.left().node());
181 node->ReplaceInput(0, msub.left().node());
182 node->ReplaceInput(1, msub.right().node());
183 return Changed(node);
190 Int64BinopMatcher m(node);
195 Int64BinopMatcher msub(m.left().node());
196 node->ReplaceInput(0, msub.left().node());
197 node->ReplaceInput(1, msub.right().node());
198 return Changed(node);
205 return ReduceInt32Add(node);
207 return ReduceInt32Sub(node);
209 Int32BinopMatcher m(node);
210 if (m.right().Is(0)) return Replace(m.right().node()); // x * 0 => 0
211 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1 => x
216 node->ReplaceInput(0, Int32Constant(0));
217 node->ReplaceInput(1, m.left().node());
218 NodeProperties::ChangeOp(node, machine()->Int32Sub());
219 return Changed(node);
222 node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value())));
223 NodeProperties::ChangeOp(node, machine()->Word32Shl());
224 Reduction reduction = ReduceWord32Shl(node);
225 return reduction.Changed() ? reduction : Changed(node);
230 return ReduceInt32Div(node);
232 return ReduceUint32Div(node);
234 return ReduceInt32Mod(node);
236 return ReduceUint32Mod(node);
238 Int32BinopMatcher m(node);
243 Int32BinopMatcher msub(m.left().node());
244 node->ReplaceInput(0, msub.left().node());
245 node->ReplaceInput(1, msub.right().node());
246 return Changed(node);
249 Int32BinopMatcher msub(m.right().node());
250 node->ReplaceInput(0, msub.right().node());
251 node->ReplaceInput(1, msub.left().node());
252 return Changed(node);
258 Int32BinopMatcher m(node);
263 Int32BinopMatcher msub(m.left().node());
264 node->ReplaceInput(0, msub.left().node());
265 node->ReplaceInput(1, msub.right().node());
266 return Changed(node);
269 Int32BinopMatcher msub(m.right().node());
270 node->ReplaceInput(0, msub.right().node());
271 node->ReplaceInput(1, msub.left().node());
272 return Changed(node);
278 Uint32BinopMatcher m(node);
286 Int32BinopMatcher mleft(m.left().node());
293 node->ReplaceInput(0, mleft.left().node());
294 node->ReplaceInput(1, Uint32Constant(c << k));
295 return Changed(node);
303 Uint32BinopMatcher m(node);
313 Float64BinopMatcher m(node);
315 return Replace(m.right().node());
323 Float64BinopMatcher m(node);
325 return Replace(m.left().node()); // x - 0 => x
328 return Replace(m.right().node());
331 return Replace(m.left().node());
339 Float64BinopMatcher m(node);
341 node->ReplaceInput(0, Float64Constant(-0.0));
342 node->ReplaceInput(1, m.left().node());
343 NodeProperties::ChangeOp(node, machine()->Float64Sub());
344 return Changed(node);
346 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x
348 return Replace(m.right().node());
356 Float64BinopMatcher m(node);
357 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x
359 return Replace(m.right().node());
362 return Replace(m.left().node());
370 Float64BinopMatcher m(node);
375 return Replace(m.right().node());
378 return Replace(m.left().node());
386 Float32Matcher m(node->InputAt(0));
391 Float64Matcher m(node->InputAt(0));
393 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
397 Float64Matcher m(node->InputAt(0));
399 if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0));
403 Int32Matcher m(node->InputAt(0));
408 Int32Matcher m(node->InputAt(0));
413 Uint32Matcher m(node->InputAt(0));
418 Uint32Matcher m(node->InputAt(0));
423 return ReduceTruncateFloat64ToInt32(node);
425 Int64Matcher m(node->InputAt(0));
427 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0));
431 Float64Matcher m(node->InputAt(0));
433 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0));
437 return ReduceFloat64InsertLowWord32(node);
439 return ReduceFloat64InsertHighWord32(node);
441 return ReduceStore(node);
445 return ReduceFloat64Compare(node);
453 Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) {
454 DCHECK_EQ(IrOpcode::kInt32Add, node->opcode());
455 Int32BinopMatcher m(node);
456 if (m.right().Is(0)) return Replace(m.left().node()); // x + 0 => x
462 Int32BinopMatcher mleft(m.left().node());
464 node->ReplaceInput(0, m.right().node());
465 node->ReplaceInput(1, mleft.right().node());
466 NodeProperties::ChangeOp(node, machine()->Int32Sub());
467 Reduction const reduction = ReduceInt32Sub(node);
468 return reduction.Changed() ? reduction : Changed(node);
472 Int32BinopMatcher mright(m.right().node());
474 node->ReplaceInput(1, mright.right().node());
475 NodeProperties::ChangeOp(node, machine()->Int32Sub());
476 Reduction const reduction = ReduceInt32Sub(node);
477 return reduction.Changed() ? reduction : Changed(node);
484 Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) {
485 DCHECK_EQ(IrOpcode::kInt32Sub, node->opcode());
486 Int32BinopMatcher m(node);
487 if (m.right().Is(0)) return Replace(m.left().node()); // x - 0 => x
494 node->ReplaceInput(1, Int32Constant(-m.right().Value()));
495 NodeProperties::ChangeOp(node, machine()->Int32Add());
496 Reduction const reduction = ReduceInt32Add(node);
497 return reduction.Changed() ? reduction : Changed(node);
503 Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) {
504 Int32BinopMatcher m(node);
505 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0
506 if (m.right().Is(0)) return Replace(m.right().node()); // x / 0 => 0
507 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x
513 Node* const zero = Int32Constant(0);
514 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
517 node->ReplaceInput(0, Int32Constant(0));
518 node->ReplaceInput(1, m.left().node());
519 node->TrimInputCount(2);
520 NodeProperties::ChangeOp(node, machine()->Int32Sub());
521 return Changed(node);
525 Node* const dividend = m.left().node();
526 Node* quotient = dividend;
539 node->ReplaceInput(0, Int32Constant(0));
540 node->ReplaceInput(1, quotient);
541 node->TrimInputCount(2);
542 NodeProperties::ChangeOp(node, machine()->Int32Sub());
543 return Changed(node);
551 Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
552 Uint32BinopMatcher m(node);
553 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0
554 if (m.right().Is(0)) return Replace(m.right().node()); // x / 0 => 0
555 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x
561 Node* const zero = Int32Constant(0);
562 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
565 Node* const dividend = m.left().node();
568 node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value())));
569 node->TrimInputCount(2);
570 NodeProperties::ChangeOp(node, machine()->Word32Shr());
571 return Changed(node);
580 Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {
581 Int32BinopMatcher m(node);
582 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0
583 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0
592 Node* const dividend = m.left().node();
596 Node* const zero = Int32Constant(0);
597 node->ReplaceInput(
599 node->ReplaceInput(
601 node->ReplaceInput(2, Word32And(dividend, mask));
603 node,
606 Node* quotient = Int32Div(dividend, divisor);
607 DCHECK_EQ(dividend, node->InputAt(0));
608 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor)));
609 node->TrimInputCount(2);
610 NodeProperties::ChangeOp(node, machine()->Int32Sub());
612 return Changed(node);
618 Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
619 Uint32BinopMatcher m(node);
620 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0
621 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0
629 Node* const dividend = m.left().node();
632 node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1));
633 node->TrimInputCount(2);
634 NodeProperties::ChangeOp(node, machine()->Word32And());
636 Node* quotient = Uint32Div(dividend, divisor);
637 DCHECK_EQ(dividend, node->InputAt(0));
638 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor)));
639 node->TrimInputCount(2);
640 NodeProperties::ChangeOp(node, machine()->Int32Sub());
642 return Changed(node);
648 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
649 Float64Matcher m(node->InputAt(0));
651 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
653 Node* const phi = m.node();
655 if (phi->OwnedBy(node)) {
662 Node* input = graph()->NewNode(node->op(), phi->InputAt(i));
679 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
681 StoreRepresentationOf(node->op()).representation();
682 Node* const value = node->InputAt(2);
690 node->ReplaceInput(2, m.left().node());
691 return Changed(node);
701 Int32BinopMatcher mleft(m.left().node());
703 node->ReplaceInput(2, mleft.left().node());
704 return Changed(node);
716 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {
717 switch (node->opcode()) {
720 Int32BinopMatcher m(node);
728 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0);
734 Int32BinopMatcher m(node);
742 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0);
753 Reduction MachineOperatorReducer::ReduceWord32Shifts(Node* node) {
754 DCHECK((node->opcode() == IrOpcode::kWord32Shl) ||
755 (node->opcode() == IrOpcode::kWord32Shr) ||
756 (node->opcode() == IrOpcode::kWord32Sar));
760 Int32BinopMatcher m(node);
762 Int32BinopMatcher mright(m.right().node());
764 node->ReplaceInput(1, mright.left().node());
765 return Changed(node);
773 Reduction MachineOperatorReducer::ReduceWord32Shl(Node* node) {
774 DCHECK_EQ(IrOpcode::kWord32Shl, node->opcode());
775 Int32BinopMatcher m(node);
776 if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x
784 Int32BinopMatcher mleft(m.left().node());
786 node->ReplaceInput(0, mleft.left().node());
787 node->ReplaceInput(1,
789 NodeProperties::ChangeOp(node, machine()->Word32And());
790 Reduction reduction = ReduceWord32And(node);
791 return reduction.Changed() ? reduction : Changed(node);
795 return ReduceWord32Shifts(node);
799 Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) {
800 Int32BinopMatcher m(node);
801 if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x
806 Int32BinopMatcher mleft(m.left().node());
810 node->ReplaceInput(0, Int32Constant(0));
811 node->ReplaceInput(1, mleft.left().node());
812 NodeProperties::ChangeOp(node, machine()->Int32Sub());
813 Reduction const reduction = ReduceInt32Sub(node);
814 return reduction.Changed() ? reduction : Changed(node);
818 LoadRepresentationOf(mleft.left().node()->op());
822 return Replace(mleft.left().node());
827 return Replace(mleft.left().node());
831 return ReduceWord32Shifts(node);
835 Reduction MachineOperatorReducer::ReduceWord32And(Node* node) {
836 DCHECK_EQ(IrOpcode::kWord32And, node->opcode());
837 Int32BinopMatcher m(node);
838 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0
839 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x
841 return Replace(m.left().node());
846 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x
848 Int32BinopMatcher mleft(m.left().node());
850 node->ReplaceInput(0, mleft.left().node());
851 node->ReplaceInput(
853 Reduction const reduction = ReduceWord32And(node);
854 return reduction.Changed() ? reduction : Changed(node);
860 Uint32BinopMatcher mleft(m.left().node());
864 return Replace(mleft.node());
867 Int32BinopMatcher mleft(m.left().node());
871 node->ReplaceInput(0, Word32And(mleft.left().node(), m.right().node()));
872 node->ReplaceInput(1, mleft.right().node());
873 NodeProperties::ChangeOp(node, machine()->Int32Add());
874 Reduction const reduction = ReduceInt32Add(node);
875 return reduction.Changed() ? reduction : Changed(node);
878 Int32BinopMatcher mleftleft(mleft.left().node());
881 node->ReplaceInput(0,
882 Word32And(mleft.right().node(), m.right().node()));
883 node->ReplaceInput(1, mleftleft.node());
884 NodeProperties::ChangeOp(node, machine()->Int32Add());
885 Reduction const reduction = ReduceInt32Add(node);
886 return reduction.Changed() ? reduction : Changed(node);
890 Int32BinopMatcher mleftright(mleft.right().node());
893 node->ReplaceInput(0,
894 Word32And(mleft.left().node(), m.right().node()));
895 node->ReplaceInput(1, mleftright.node());
896 NodeProperties::ChangeOp(node, machine()->Int32Add());
897 Reduction const reduction = ReduceInt32Add(node);
898 return reduction.Changed() ? reduction : Changed(node);
902 Int32BinopMatcher mleftleft(mleft.left().node());
905 node->ReplaceInput(0,
906 Word32And(mleft.right().node(), m.right().node()));
907 node->ReplaceInput(1, mleftleft.node());
908 NodeProperties::ChangeOp(node, machine()->Int32Add());
909 Reduction const reduction = ReduceInt32Add(node);
910 return reduction.Changed() ? reduction : Changed(node);
914 Int32BinopMatcher mleftright(mleft.right().node());
917 node->ReplaceInput(0,
918 Word32And(mleft.left().node(), m.right().node()));
919 node->ReplaceInput(1, mleftright.node());
920 NodeProperties::ChangeOp(node, machine()->Int32Add());
921 Reduction const reduction = ReduceInt32Add(node);
922 return reduction.Changed() ? reduction : Changed(node);
926 Int32BinopMatcher mleft(m.left().node());
929 return Replace(mleft.node());
937 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) {
938 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode());
939 Int32BinopMatcher m(node);
940 if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x
941 if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1
945 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x
947 Node* shl = nullptr;
948 Node* shr = nullptr;
954 shl = m.left().node();
955 shr = m.right().node();
957 shl = m.right().node();
958 shr = m.left().node();
965 if (mshl.left().node() != mshr.left().node()) return NoChange();
971 Node* sub = nullptr;
972 Node* y = nullptr;
974 sub = mshl.right().node();
975 y = mshr.right().node();
977 sub = mshr.right().node();
978 y = mshl.right().node();
984 if (!msub.left().Is(32) || msub.right().node() != y) return NoChange();
987 node->ReplaceInput(0, mshl.left().node());
988 node->ReplaceInput(1, mshr.right().node());
989 NodeProperties::ChangeOp(node, machine()->Word32Ror());
990 return Changed(node);
994 Reduction MachineOperatorReducer::ReduceFloat64InsertLowWord32(Node* node) {
995 DCHECK_EQ(IrOpcode::kFloat64InsertLowWord32, node->opcode());
996 Float64Matcher mlhs(node->InputAt(0));
997 Uint32Matcher mrhs(node->InputAt(1));
1007 Reduction MachineOperatorReducer::ReduceFloat64InsertHighWord32(Node* node) {
1008 DCHECK_EQ(IrOpcode::kFloat64InsertHighWord32, node->opcode());
1009 Float64Matcher mlhs(node->InputAt(0));
1010 Uint32Matcher mrhs(node->InputAt(1));
1034 Reduction MachineOperatorReducer::ReduceFloat64Compare(Node* node) {
1035 DCHECK((IrOpcode::kFloat64Equal == node->opcode()) ||
1036 (IrOpcode::kFloat64LessThan == node->opcode()) ||
1037 (IrOpcode::kFloat64LessThanOrEqual == node->opcode()));
1043 Float64BinopMatcher m(node);
1050 switch (node->opcode()) {
1052 NodeProperties::ChangeOp(node, machine()->Float32Equal());
1055 NodeProperties::ChangeOp(node, machine()->Float32LessThan());
1058 NodeProperties::ChangeOp(node, machine()->Float32LessThanOrEqual());
1063 node->ReplaceInput(
1067 node->ReplaceInput(
1071 return Changed(node);