Lines Matching refs:node

20 #include "src/compiler/node-matchers.h"
21 #include "src/compiler/node-properties.h"
77 Reduction ReduceWordNAnd(Node* node) { return r_->ReduceWord32And(node); }
78 Reduction ReduceIntNAdd(Node* node) { return r_->ReduceInt32Add(node); }
79 Reduction TryMatchWordNRor(Node* node) { return r_->TryMatchWord32Ror(node); }
137 Reduction ReduceWordNAnd(Node* node) { return r_->ReduceWord64And(node); }
138 Reduction ReduceIntNAdd(Node* node) { return r_->ReduceInt64Add(node); }
139 Reduction TryMatchWordNRor(Node* node) {
207 Node* const node = graph()->NewNode(machine()->Word32And(), lhs, rhs);
208 Reduction const reduction = ReduceWord32And(node);
209 return reduction.Changed() ? reduction.replacement() : node;
227 Node* const node = graph()->NewNode(machine()->Word64And(), lhs, rhs);
228 Reduction const reduction = ReduceWord64And(node);
229 return reduction.Changed() ? reduction.replacement() : node;
233 Node* const node = graph()->NewNode(machine()->Int32Add(), lhs, rhs);
234 Reduction const reduction = ReduceInt32Add(node);
235 return reduction.Changed() ? reduction.replacement() : node;
239 Node* const node = graph()->NewNode(machine()->Int32Sub(), lhs, rhs);
240 Reduction const reduction = ReduceInt32Sub(node);
241 return reduction.Changed() ? reduction.replacement() : node;
287 Node* const node = graph()->NewNode(machine()->TruncateInt64ToInt32(), value);
288 Reduction const reduction = ReduceTruncateInt64ToInt32(node);
289 return reduction.Changed() ? reduction.replacement() : node;
309 Reduction MachineOperatorReducer::Reduce(Node* node) {
310 switch (node->opcode()) {
312 return ReduceProjection(ProjectionIndexOf(node->op()), node->InputAt(0));
314 return ReduceWord32And(node);
316 return ReduceWord64And(node);
318 return ReduceWord32Or(node);
320 return ReduceWord64Or(node);
322 return ReduceWord32Xor(node);
324 return ReduceWord64Xor(node);
326 return ReduceWord32Shl(node);
328 return ReduceWord64Shl(node);
330 return ReduceWord32Shr(node);
332 return ReduceWord64Shr(node);
334 return ReduceWord32Sar(node);
336 return ReduceWord64Sar(node);
338 Int32BinopMatcher m(node);
339 if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x
347 return ReduceWord32Equal(node);
350 Int64BinopMatcher m(node);
356 Int64BinopMatcher msub(m.left().node());
357 node->ReplaceInput(0, msub.left().node());
358 node->ReplaceInput(1, msub.right().node());
359 return Changed(node);
365 if (!ObjectsMayAlias(m.left().node(), m.right().node())) {
371 return ReduceInt32Add(node);
373 return ReduceInt64Add(node);
375 return ReduceInt32Sub(node);
377 return ReduceInt64Sub(node);
379 Int32BinopMatcher m(node);
380 if (m.right().Is(0)) return Replace(m.right().node()); // x * 0 => 0
381 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1 => x
387 node->ReplaceInput(0, Int32Constant(0));
388 node->ReplaceInput(1, m.left().node());
389 NodeProperties::ChangeOp(node, machine()->Int32Sub());
390 return Changed(node);
393 node->ReplaceInput(1, Int32Constant(base::bits::WhichPowerOfTwo(
395 NodeProperties::ChangeOp(node, machine()->Word32Shl());
396 return Changed(node).FollowedBy(ReduceWord32Shl(node));
400 Int32BinopMatcher n(m.left().node());
401 if (n.right().HasResolvedValue() && m.OwnsInput(m.left().node())) {
402 node->ReplaceInput(
405 node->ReplaceInput(0, n.left().node());
406 return Changed(node);
412 Int32BinopMatcher m(node);
414 node->ReplaceInput(1, m.left().node());
415 NodeProperties::ChangeOp(node, machine()->Int32AddWithOverflow());
416 return Changed(node);
419 node->ReplaceInput(0, Int32Constant(0));
420 node->ReplaceInput(1, m.left().node());
421 NodeProperties::ChangeOp(node, machine()->Int32SubWithOverflow());
422 return Changed(node);
427 return ReduceInt64Mul(node);
429 return ReduceInt32Div(node);
431 return ReduceUint32Div(node);
433 return ReduceInt32Mod(node);
435 return ReduceUint32Mod(node);
437 Int32BinopMatcher m(node);
445 Int32BinopMatcher mleftmatcher(m.left().node());
451 return ReduceWord32Comparisons(node);
454 Int32BinopMatcher m(node);
460 return ReduceWord32Comparisons(node);
463 Uint32BinopMatcher m(node);
472 Int32BinopMatcher mleft(m.left().node());
479 node->ReplaceInput(0, mleft.left().node());
480 node->ReplaceInput(1, Uint32Constant(c << k));
481 return Changed(node);
486 return ReduceWord32Comparisons(node);
489 Uint32BinopMatcher m(node);
497 return ReduceWord32Comparisons(node);
500 Float32BinopMatcher m(node);
503 return Replace(m.left().node()); // x - 0 => x
523 mright0.right().node()));
528 node->RemoveInput(0);
529 NodeProperties::ChangeOp(node, machine()->Float32Neg());
530 return Changed(node);
535 Float64BinopMatcher m(node);
549 Float64BinopMatcher m(node);
552 return Replace(m.left().node()); // x - 0 => x
572 mright0.right().node()));
577 node->RemoveInput(0);
578 NodeProperties::ChangeOp(node, machine()->Float64Neg());
579 return Changed(node);
584 Float64BinopMatcher m(node);
586 return Replace(m.left().node()); // x * 1.0 => x
588 node->ReplaceInput(0, Float64Constant(-0.0));
589 node->ReplaceInput(1, m.left().node());
590 NodeProperties::ChangeOp(node, machine()->Float64Sub());
591 return Changed(node);
601 node->ReplaceInput(1, m.left().node());
602 NodeProperties::ChangeOp(node, machine()->Float64Add());
603 return Changed(node);
608 Float64BinopMatcher m(node);
610 return Replace(m.left().node()); // x / 1.0 => x
623 node->RemoveInput(1);
624 NodeProperties::ChangeOp(node, machine()->Float64Neg());
625 return Changed(node);
631 node->ReplaceInput(1, Float64Constant(1.0 / m.right().ResolvedValue()));
632 NodeProperties::ChangeOp(node, machine()->Float64Mul());
633 return Changed(node);
638 Float64BinopMatcher m(node);
655 Float64Matcher m(node->InputAt(0));
661 Float64Matcher m(node->InputAt(0));
667 Float64Matcher m(node->InputAt(0));
673 Float64Matcher m(node->InputAt(0));
679 Float64Matcher m(node->InputAt(0));
685 Float64Matcher m(node->InputAt(0));
691 Float64BinopMatcher m(node);
705 Float64Matcher m(node->InputAt(0));
711 Float64Matcher m(node->InputAt(0));
717 Float64Matcher m(node->InputAt(0));
723 Float64Matcher m(node->InputAt(0));
729 Float64Matcher m(node->InputAt(0));
735 Float64Matcher m(node->InputAt(0));
741 Float64Matcher m(node->InputAt(0));
747 Float64Matcher m(node->InputAt(0));
753 Float64Matcher m(node->InputAt(0));
759 Float64BinopMatcher m(node);
766 node->ReplaceInput(1, m.left().node());
767 NodeProperties::ChangeOp(node, machine()->Float64Mul());
768 return Changed(node);
771 return Replace(Float64PowHalf(m.left().node()));
776 Float64Matcher m(node->InputAt(0));
782 Float64Matcher m(node->InputAt(0));
788 Float64Matcher m(node->InputAt(0));
794 Float64Matcher m(node->InputAt(0));
800 Float32Matcher m(node->InputAt(0));
810 Float64Matcher m(node->InputAt(0));
813 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
817 Float64Matcher m(node->InputAt(0));
820 if (m.IsChangeInt64ToFloat64()) return Replace(m.node()->InputAt(0));
824 Float64Matcher m(node->InputAt(0));
827 if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0));
831 Int32Matcher m(node->InputAt(0));
837 Int32Matcher m(node->InputAt(0));
842 Int32Matcher m(node->InputAt(0));
847 Int64Matcher m(node->InputAt(0));
850 if (m.IsChangeFloat64ToInt64()) return Replace(m.node()->InputAt(0));
854 Uint32Matcher m(node->InputAt(0));
860 Uint32Matcher m(node->InputAt(0));
866 Float64Matcher m(node->InputAt(0));
869 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
873 return ReduceTruncateInt64ToInt32(node);
875 Float64Matcher m(node->InputAt(0));
883 return Replace(m.node()->InputAt(0));
887 Float64Matcher m(node->InputAt(0));
891 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
895 return ReduceFloat64InsertLowWord32(node);
897 return ReduceFloat64InsertHighWord32(node);
900 return ReduceStore(node);
904 return ReduceFloat64Compare(node);
906 return ReduceFloat64RoundDown(node);
909 NodeMatcher m(node->InputAt(0));
911 RelaxEffectsAndControls(node);
921 return ReduceConditional(node);
923 Int64BinopMatcher m(node);
928 return ReduceWord64Comparisons(node);
931 Int64BinopMatcher m(node);
936 return ReduceWord64Comparisons(node);
939 Uint64BinopMatcher m(node);
944 return ReduceWord64Comparisons(node);
947 Uint64BinopMatcher m(node);
952 return ReduceWord64Comparisons(node);
958 Int32Matcher match(node->InputAt(0));
961 return Replace(node->InputAt(2));
963 return Replace(node->InputAt(1));
974 Reduction MachineOperatorReducer::ReduceTruncateInt64ToInt32(Node* node) {
975 Int64Matcher m(node->InputAt(0));
978 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0));
982 Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) {
983 DCHECK_EQ(IrOpcode::kInt32Add, node->opcode());
984 Int32BinopMatcher m(node);
985 if (m.right().Is(0)) return Replace(m.left().node()); // x + 0 => x
991 Int32BinopMatcher mleft(m.left().node());
993 node->ReplaceInput(0, m.right().node());
994 node->ReplaceInput(1, mleft.right().node());
995 NodeProperties::ChangeOp(node, machine()->Int32Sub());
996 return Changed(node).FollowedBy(ReduceInt32Sub(node));
1000 Int32BinopMatcher mright(m.right().node());
1002 node->ReplaceInput(1, mright.right().node());
1003 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1004 return Changed(node).FollowedBy(ReduceInt32Sub(node));
1009 Int32BinopMatcher n(m.left().node());
1010 if (n.right().HasResolvedValue() && m.OwnsInput(m.left().node())) {
1011 node->ReplaceInput(
1014 node->ReplaceInput(0, n.left().node());
1015 return Changed(node);
1022 Reduction MachineOperatorReducer::ReduceInt64Add(Node* node) {
1023 DCHECK_EQ(IrOpcode::kInt64Add, node->opcode());
1024 Int64BinopMatcher m(node);
1025 if (m.right().Is(0)) return Replace(m.left().node()); // x + 0 => 0
1032 Int64BinopMatcher n(m.left().node());
1033 if (n.right().HasResolvedValue() && m.OwnsInput(m.left().node())) {
1034 node->ReplaceInput(
1037 node->ReplaceInput(0, n.left().node());
1038 return Changed(node);
1044 Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) {
1045 DCHECK_EQ(IrOpcode::kInt32Sub, node->opcode());
1046 Int32BinopMatcher m(node);
1047 if (m.right().Is(0)) return Replace(m.left().node()); // x - 0 => x
1054 node->ReplaceInput(
1057 NodeProperties::ChangeOp(node, machine()->Int32Add());
1058 return Changed(node).FollowedBy(ReduceInt32Add(node));
1063 Reduction MachineOperatorReducer::ReduceInt64Sub(Node* node) {
1064 DCHECK_EQ(IrOpcode::kInt64Sub, node->opcode());
1065 Int64BinopMatcher m(node);
1066 if (m.right().Is(0)) return Replace(m.left().node()); // x - 0 => x
1073 node->ReplaceInput(
1076 NodeProperties::ChangeOp(node, machine()->Int64Add());
1077 return Changed(node).FollowedBy(ReduceInt64Add(node));
1082 Reduction MachineOperatorReducer::ReduceInt64Mul(Node* node) {
1083 DCHECK_EQ(IrOpcode::kInt64Mul, node->opcode());
1084 Int64BinopMatcher m(node);
1085 if (m.right().Is(0)) return Replace(m.right().node()); // x * 0 => 0
1086 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1 => x
1092 node->ReplaceInput(0, Int64Constant(0));
1093 node->ReplaceInput(1, m.left().node());
1094 NodeProperties::ChangeOp(node, machine()->Int64Sub());
1095 return Changed(node);
1098 node->ReplaceInput(
1101 NodeProperties::ChangeOp(node, machine()->Word64Shl());
1102 return Changed(node).FollowedBy(ReduceWord64Shl(node));
1106 Int64BinopMatcher n(m.left().node());
1107 if (n.right().HasResolvedValue() && m.OwnsInput(m.left().node())) {
1108 node->ReplaceInput(
1111 node->ReplaceInput(0, n.left().node());
1112 return Changed(node);
1118 Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) {
1119 Int32BinopMatcher m(node);
1120 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0
1121 if (m.right().Is(0)) return Replace(m.right().node()); // x / 0 => 0
1122 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x
1129 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
1132 node->ReplaceInput(0, Int32Constant(0));
1133 node->ReplaceInput(1, m.left().node());
1134 node->TrimInputCount(2);
1135 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1136 return Changed(node);
1140 Node* const dividend = m.left().node();
1154 node->ReplaceInput(0, Int32Constant(0));
1155 node->ReplaceInput(1, quotient);
1156 node->TrimInputCount(2);
1157 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1158 return Changed(node);
1165 Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
1166 Uint32BinopMatcher m(node);
1167 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0
1168 if (m.right().Is(0)) return Replace(m.right().node()); // x / 0 => 0
1169 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x
1176 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
1179 Node* const dividend = m.left().node();
1182 node->ReplaceInput(1, Uint32Constant(base::bits::WhichPowerOfTwo(
1184 node->TrimInputCount(2);
1185 NodeProperties::ChangeOp(node, machine()->Word32Shr());
1186 return Changed(node);
1194 Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {
1195 Int32BinopMatcher m(node);
1196 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0
1197 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0
1206 Node* const dividend = m.left().node();
1220 DCHECK_EQ(dividend, node->InputAt(0));
1221 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor)));
1222 node->TrimInputCount(2);
1223 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1225 return Changed(node);
1230 Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
1231 Uint32BinopMatcher m(node);
1232 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0
1233 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0
1241 Node* const dividend = m.left().node();
1244 node->ReplaceInput(1, Uint32Constant(m.right().ResolvedValue() - 1));
1245 node->TrimInputCount(2);
1246 NodeProperties::ChangeOp(node, machine()->Word32And());
1249 DCHECK_EQ(dividend, node->InputAt(0));
1250 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor)));
1251 node->TrimInputCount(2);
1252 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1254 return Changed(node);
1259 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
1260 NodeMatcher nm(node);
1263 nm.IsStore() ? StoreRepresentationOf(node->op()).representation()
1264 : UnalignedStoreRepresentationOf(node->op());
1267 Node* const value = node->InputAt(value_input);
1277 node->ReplaceInput(value_input, m.left().node());
1278 return Changed(node);
1288 Int32BinopMatcher mleft(m.left().node());
1290 node->ReplaceInput(value_input, mleft.left().node());
1291 return Changed(node);
1302 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {
1303 switch (node->opcode()) {
1306 Int32BinopMatcher m(node);
1314 return Replace(index == 0 ? m.left().node() : m.right().node());
1320 Int32BinopMatcher m(node);
1328 return Replace(index == 0 ? m.left().node() : m.right().node());
1334 Int32BinopMatcher m(node);
1342 return Replace(m.right().node());
1345 return index == 0 ? Replace(m.left().node()) : ReplaceInt32(0);
1375 Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* node) {
1376 DCHECK(node->opcode() == IrOpcode::kInt32LessThan ||
1377 node->opcode() == IrOpcode::kInt32LessThanOrEqual ||
1378 node->opcode() == IrOpcode::kUint32LessThan ||
1379 node->opcode() == IrOpcode::kUint32LessThanOrEqual);
1380 Int32BinopMatcher m(node);
1384 Int32BinopMatcher mleft(m.left().node());
1385 Int32BinopMatcher mright(m.right().node());
1388 node->ReplaceInput(0, mleft.left().node());
1389 node->ReplaceInput(1, mright.left().node());
1390 return Changed(node);
1397 m.left().node()->UseCount() == 1) {
1399 Int32BinopMatcher mleft(m.left().node());
1403 node->ReplaceInput(0, mleft.left().node());
1404 node->ReplaceInput(1, Int32Constant(right << shift));
1405 return Changed(node);
1413 m.right().node()->UseCount() == 1) {
1415 Int32BinopMatcher mright(m.right().node());
1419 node->ReplaceInput(0, Int32Constant(left << shift));
1420 node->ReplaceInput(1, mright.left().node());
1421 return Changed(node);
1446 Reduction MachineOperatorReducer::ReduceWord64Comparisons(Node* node) {
1447 DCHECK(node->opcode() == IrOpcode::kInt64LessThan ||
1448 node->opcode() == IrOpcode::kInt64LessThanOrEqual ||
1449 node->opcode() == IrOpcode::kUint64LessThan ||
1450 node->opcode() == IrOpcode::kUint64LessThanOrEqual);
1451 Int64BinopMatcher m(node);
1457 node->ReplaceInput(0, NodeProperties::GetValueInput(m.left().node(), 0));
1458 node->ReplaceInput(1, NodeProperties::GetValueInput(m.right().node(), 0));
1459 NodeProperties::ChangeOp(node,
1460 Map64To32Comparison(node->op(), sign_extended));
1461 return Changed(node).FollowedBy(Reduce(node));
1468 Int64BinopMatcher mleft(m.left().node());
1469 Int64BinopMatcher mright(m.right().node());
1472 node->ReplaceInput(0, mleft.left().node());
1473 node->ReplaceInput(1, mright.left().node());
1474 return Changed(node);
1481 Reduction MachineOperatorReducer::ReduceWord32Shifts(Node* node) {
1482 DCHECK((node->opcode() == IrOpcode::kWord32Shl) ||
1483 (node->opcode() == IrOpcode::kWord32Shr) ||
1484 (node->opcode() == IrOpcode::kWord32Sar));
1488 Int32BinopMatcher m(node);
1490 Int32BinopMatcher mright(m.right().node());
1492 node->ReplaceInput(1, mright.left().node());
1493 return Changed(node);
1500 Reduction MachineOperatorReducer::ReduceWord32Shl(Node* node) {
1501 DCHECK_EQ(IrOpcode::kWord32Shl, node->opcode());
1502 Int32BinopMatcher m(node);
1503 if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x
1510 Int32BinopMatcher mleft(m.left().node());
1520 Node* x = mleft.left().node();
1526 node->ReplaceInput(0, x);
1527 node->ReplaceInput(1, Uint32Constant(k - l));
1528 NodeProperties::ChangeOp(node, machine()->Word32Sar());
1529 return Changed(node).FollowedBy(ReduceWord32Sar(node));
1532 node->ReplaceInput(0, x);
1533 node->ReplaceInput(1, Uint32Constant(l - k));
1534 return Changed(node);
1541 node->ReplaceInput(0, mleft.left().node());
1542 node->ReplaceInput(1,
1545 NodeProperties::ChangeOp(node, machine()->Word32And());
1546 return Changed(node).FollowedBy(ReduceWord32And(node));
1550 return ReduceWord32Shifts(node);
1553 Reduction MachineOperatorReducer::ReduceWord64Shl(Node* node) {
1554 DCHECK_EQ(IrOpcode::kWord64Shl, node->opcode());
1555 Int64BinopMatcher m(node);
1556 if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x
1563 Int64BinopMatcher mleft(m.left().node());
1573 Node* x = mleft.left().node();
1579 node->ReplaceInput(0, x);
1580 node->ReplaceInput(1, Uint64Constant(k - l));
1581 NodeProperties::ChangeOp(node, machine()->Word64Sar());
1582 return Changed(node).FollowedBy(ReduceWord64Sar(node));
1585 node->ReplaceInput(0, x);
1586 node->ReplaceInput(1, Uint64Constant(l - k));
1587 return Changed(node);
1594 node->ReplaceInput(0, mleft.left().node());
1595 node->ReplaceInput(1, Uint64Constant(std::numeric_limits<uint64_t>::max()
1597 NodeProperties::ChangeOp(node, machine()->Word64And());
1598 return Changed(node).FollowedBy(ReduceWord64And(node));
1604 Reduction MachineOperatorReducer::ReduceWord32Shr(Node* node) {
1605 Uint32BinopMatcher m(node);
1606 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x
1612 Uint32BinopMatcher mleft(m.left().node());
1622 return ReduceWord32Shifts(node);
1625 Reduction MachineOperatorReducer::ReduceWord64Shr(Node* node) {
1626 DCHECK_EQ(IrOpcode::kWord64Shr, node->opcode());
1627 Uint64BinopMatcher m(node);
1628 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x
1636 Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) {
1637 Int32BinopMatcher m(node);
1638 if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x
1644 Int32BinopMatcher mleft(m.left().node());
1648 node->ReplaceInput(0, Int32Constant(0));
1649 node->ReplaceInput(1, mleft.left().node());
1650 NodeProperties::ChangeOp(node, machine()->Int32Sub());
1651 return Changed(node).FollowedBy(ReduceInt32Sub(node));
1655 LoadRepresentationOf(mleft.left().node()->op());
1659 return Replace(mleft.left().node());
1664 return Replace(mleft.left().node());
1668 return ReduceWord32Shifts(node);
1671 Reduction MachineOperatorReducer::ReduceWord64Sar(Node* node) {
1672 Int64BinopMatcher m(node);
1673 if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x
1682 Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
1686 typename A::IntNBinopMatcher m(node);
1687 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0
1688 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x
1690 return Replace(m.left().node());
1695 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x
1697 typename A::IntNBinopMatcher mleft(m.left().node());
1699 node->ReplaceInput(0, mleft.left().node());
1700 node->ReplaceInput(1, a.IntNConstant(m.right().ResolvedValue() &
1702 return Changed(node).FollowedBy(a.ReduceWordNAnd(node));
1709 typename A::UintNBinopMatcher mleft(m.left().node());
1714 return Replace(mleft.node());
1717 typename A::IntNBinopMatcher mleft(m.left().node());
1722 node->ReplaceInput(0,
1723 a.WordNAnd(mleft.left().node(), m.right().node()));
1724 node->ReplaceInput(1, mleft.right().node());
1725 NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
1726 return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
1729 typename A::IntNBinopMatcher mleftleft(mleft.left().node());
1732 node->ReplaceInput(
1733 0, a.WordNAnd(mleft.right().node(), m.right().node()));
1734 node->ReplaceInput(1, mleftleft.node());
1735 NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
1736 return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
1740 typename A::IntNBinopMatcher mleftright(mleft.right().node());
1743 node->ReplaceInput(0,
1744 a.WordNAnd(mleft.left().node(), m.right().node()));
1745 node->ReplaceInput(1, mleftright.node());
1746 NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
1747 return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
1751 typename A::IntNBinopMatcher mleftleft(mleft.left().node());
1754 node->ReplaceInput(
1755 0, a.WordNAnd(mleft.right().node(), m.right().node()));
1756 node->ReplaceInput(1, mleftleft.node());
1757 NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
1758 return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
1762 typename A::IntNBinopMatcher mleftright(mleft.right().node());
1765 node->ReplaceInput(0,
1766 a.WordNAnd(mleft.left().node(), m.right().node()));
1767 node->ReplaceInput(1, mleftright.node());
1768 NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
1769 return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
1773 typename A::IntNBinopMatcher mleft(m.left().node());
1776 return Replace(mleft.node());
1802 static base::Optional<BitfieldCheck> Detect(Node* node) {
1810 if (node->opcode() == IrOpcode::kWord32Equal) {
1811 Uint32BinopMatcher eq(node);
1813 Uint32BinopMatcher mand(eq.left().node());
1820 NodeProperties::GetValueInput(mand.left().node(), 0), mask,
1823 return BitfieldCheck(mand.left().node(), mask, masked_value, false);
1828 if (node->opcode() == IrOpcode::kTruncateInt64ToInt32) {
1830 NodeProperties::GetValueInput(node, 0));
1832 return TryDetectShiftAndMaskOneBit<Word32Adapter>(node);
1856 static base::Optional<BitfieldCheck> TryDetectShiftAndMaskOneBit(Node* node) {
1858 if (WordNAdapter::IsWordNAnd(NodeMatcher(node))) {
1859 typename WordNAdapter::IntNBinopMatcher mand(node);
1864 typename WordNAdapter::UintNBinopMatcher shift(mand.left().node());
1868 return BitfieldCheck{shift.left().node(), mask, mask,
1872 return BitfieldCheck{mand.left().node(), 1, 1,
1882 Reduction MachineOperatorReducer::ReduceWord32And(Node* node) {
1883 DCHECK_EQ(IrOpcode::kWord32And, node->opcode());
1884 Reduction reduction = ReduceWordNAnd<Word32Adapter>(node);
1891 Int32BinopMatcher m(node);
1892 if (auto right_bitfield = BitfieldCheck::Detect(m.right().node())) {
1893 if (auto left_bitfield = BitfieldCheck::Detect(m.left().node())) {
1899 node->ReplaceInput(0, Word32And(source, combined_bitfield->mask));
1900 node->ReplaceInput(1, Int32Constant(combined_bitfield->masked_value));
1901 NodeProperties::ChangeOp(node, machine()->Word32Equal());
1902 return Changed(node).FollowedBy(ReduceWord32Equal(node));
1910 Reduction MachineOperatorReducer::ReduceWord64And(Node* node) {
1911 DCHECK_EQ(IrOpcode::kWord64And, node->opcode());
1912 return ReduceWordNAnd<Word64Adapter>(node);
1915 Reduction MachineOperatorReducer::TryMatchWord32Ror(Node* node) {
1925 DCHECK(IrOpcode::kWord32Or == node->opcode() ||
1926 IrOpcode::kWord32Xor == node->opcode());
1927 Int32BinopMatcher m(node);
1931 shl = m.left().node();
1932 shr = m.right().node();
1934 shl = m.right().node();
1935 shr = m.left().node();
1942 if (mshl.left().node() != mshr.left().node()) return NoChange();
1949 if (node->opcode() == IrOpcode::kWord32Xor &&
1957 sub = mshl.right().node();
1958 y = mshr.right().node();
1960 sub = mshr.right().node();
1961 y = mshl.right().node();
1967 if (!msub.left().Is(32) || msub.right().node() != y) return NoChange();
1968 if (node->opcode() == IrOpcode::kWord32Xor) {
1973 node->ReplaceInput(0, mshl.left().node());
1974 node->ReplaceInput(1, mshr.right().node());
1975 NodeProperties::ChangeOp(node, machine()->Word32Ror());
1976 return Changed(node);
1980 Reduction MachineOperatorReducer::ReduceWordNOr(Node* node) {
1984 typename A::IntNBinopMatcher m(node);
1985 if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x
1986 if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1
1990 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x
1996 typename A::IntNBinopMatcher mand(m.left().node());
1999 node->ReplaceInput(0, mand.left().node());
2000 return Changed(node);
2006 return a.TryMatchWordNRor(node);
2009 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) {
2010 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode());
2011 return ReduceWordNOr<Word32Adapter>(node);
2014 Reduction MachineOperatorReducer::ReduceWord64Or(Node* node) {
2015 DCHECK_EQ(IrOpcode::kWord64Or, node->opcode());
2016 return ReduceWordNOr<Word64Adapter>(node);
2020 Reduction MachineOperatorReducer::ReduceWordNXor(Node* node) {
2024 typename A::IntNBinopMatcher m(node);
2025 if (m.right().Is(0)) return Replace(m.left().node()); // x ^ 0 => x
2031 typename A::IntNBinopMatcher mleft(m.left().node());
2033 return Replace(mleft.left().node());
2037 return a.TryMatchWordNRor(node);
2040 Reduction MachineOperatorReducer::ReduceWord32Xor(Node* node) {
2041 DCHECK_EQ(IrOpcode::kWord32Xor, node->opcode());
2042 Int32BinopMatcher m(node);
2044 return Replace(Word32Equal(m.right().node(), Int32Constant(0)));
2046 return ReduceWordNXor<Word32Adapter>(node);
2049 Reduction MachineOperatorReducer::ReduceWord64Xor(Node* node) {
2050 DCHECK_EQ(IrOpcode::kWord64Xor, node->opcode());
2051 return ReduceWordNXor<Word64Adapter>(node);
2054 Reduction MachineOperatorReducer::ReduceWord32Equal(Node* node) {
2055 Int32BinopMatcher m(node);
2060 Int32BinopMatcher msub(m.left().node());
2061 node->ReplaceInput(0, msub.left().node());
2062 node->ReplaceInput(1, msub.right().node());
2063 return Changed(node);
2071 NodeProperties::GetValueInput(m.left().node(), 0),
2075 m.left().node(), static_cast<uint32_t>(m.right().ResolvedValue()));
2078 node->ReplaceInput(0, replacements->first);
2079 node->ReplaceInput(1, Uint32Constant(replacements->second));
2080 return Changed(node);
2085 if (!ObjectsMayAlias(m.left().node(), m.right().node())) {
2092 Reduction MachineOperatorReducer::ReduceFloat64InsertLowWord32(Node* node) {
2093 DCHECK_EQ(IrOpcode::kFloat64InsertLowWord32, node->opcode());
2094 Float64Matcher mlhs(node->InputAt(0));
2095 Uint32Matcher mrhs(node->InputAt(1));
2105 Reduction MachineOperatorReducer::ReduceFloat64InsertHighWord32(Node* node) {
2106 DCHECK_EQ(IrOpcode::kFloat64InsertHighWord32, node->opcode());
2107 Float64Matcher mlhs(node->InputAt(0));
2108 Uint32Matcher mrhs(node->InputAt(1));
2129 Reduction MachineOperatorReducer::ReduceFloat64Compare(Node* node) {
2130 DCHECK(IrOpcode::kFloat64Equal == node->opcode() ||
2131 IrOpcode::kFloat64LessThan == node->opcode() ||
2132 IrOpcode::kFloat64LessThanOrEqual == node->opcode());
2133 Float64BinopMatcher m(node);
2135 switch (node->opcode()) {
2159 switch (node->opcode()) {
2161 NodeProperties::ChangeOp(node, machine()->Float32Equal());
2164 NodeProperties::ChangeOp(node, machine()->Float32LessThan());
2167 NodeProperties::ChangeOp(node, machine()->Float32LessThanOrEqual());
2172 node->ReplaceInput(
2176 node->ReplaceInput(
2180 return Changed(node);
2185 Reduction MachineOperatorReducer::ReduceFloat64RoundDown(Node* node) {
2186 DCHECK_EQ(IrOpcode::kFloat64RoundDown, node->opcode());
2187 Float64Matcher m(node->InputAt(0));
2196 // Returns true if |node| is a constant whose value is 0.
2197 bool IsZero(Node* node) {
2198 switch (node->opcode()) {
2201 matcher m(node); \
2213 // If |node| is of the form "x == 0", then return "x" (in order to remove the
2218 if (IsZero(m.right().node())) {
2219 return m.left().node();
2253 void MachineOperatorReducer::SwapBranches(Node* node) {
2254 DCHECK_EQ(node->opcode(), IrOpcode::kBranch);
2255 for (Node* const use : node->uses()) {
2268 node, common()->Branch(NegateBranchHint(BranchHintOf(node->op()))));
2271 // If |node| is a branch, removes all top-level 32-bit "== 0" from |node|.
2272 Reduction MachineOperatorReducer::SimplifyBranch(Node* node) {
2273 Node* cond = node->InputAt(0);
2275 node->ReplaceInput(0, simplified->condition);
2277 switch (node->opcode()) {
2279 SwapBranches(node);
2282 NodeProperties::ChangeOp(node,
2283 common()->TrapUnless(TrapIdOf(node->op())));
2286 NodeProperties::ChangeOp(node,
2287 common()->TrapIf(TrapIdOf(node->op())));
2290 DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2292 node, common()->DeoptimizeUnless(p.reason(), p.feedback()));
2296 DeoptimizeParameters p = DeoptimizeParametersOf(node->op());
2298 node, common()->DeoptimizeIf(p.reason(), p.feedback()));
2306 return Changed(node);
2311 Reduction MachineOperatorReducer::ReduceConditional(Node* node) {
2312 DCHECK(node->opcode() == IrOpcode::kBranch ||
2313 node->opcode() == IrOpcode::kDeoptimizeIf ||
2314 node->opcode() == IrOpcode::kDeoptimizeUnless ||
2315 node->opcode() == IrOpcode::kTrapIf ||
2316 node->opcode() == IrOpcode::kTrapUnless);
2320 NodeMatcher condition(NodeProperties::GetValueInput(node, 0));
2324 ReduceConditionalN<Word64Adapter>(condition.node())) {
2325 NodeProperties::ReplaceValueInput(node, *replacement, 0);
2326 reduction = Changed(node);
2328 } else if (auto replacement = ReduceConditionalN<Word32Adapter>(node)) {
2329 NodeProperties::ReplaceValueInput(node, *replacement, 0);
2330 reduction = Changed(node);
2332 return reduction.FollowedBy(SimplifyBranch(node));
2336 base::Optional<Node*> MachineOperatorReducer::ReduceConditionalN(Node* node) {
2337 NodeMatcher condition(NodeProperties::GetValueInput(node, 0));
2339 // opposite of a 32-bit `x == 0` node. To avoid repetition, we can reuse logic
2343 ReduceWord32EqualForConstantRhs<WordNAdapter>(condition.node(), 0);
2357 typename WordNAdapter::UintNBinopMatcher mshift(mand.left().node());
2367 Node* new_input = mshift.left().node();
2387 return std::make_pair(mshift.left().node(), rhs << shift);