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/simplified-lowering.h" | 5 #include "src/compiler/simplified-lowering.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 const Operator* Float64Op(Node* node) { | 552 const Operator* Float64Op(Node* node) { |
553 return changer_->Float64OperatorFor(node->opcode()); | 553 return changer_->Float64OperatorFor(node->opcode()); |
554 } | 554 } |
555 | 555 |
556 bool CanLowerToInt32Binop(Node* node, Truncation use) { | 556 bool CanLowerToInt32Binop(Node* node, Truncation use) { |
557 return BothInputsAre(node, Type::Signed32()) && | 557 return BothInputsAre(node, Type::Signed32()) && |
558 (use.TruncatesToWord32() || | 558 (use.TruncatesToWord32() || |
559 NodeProperties::GetType(node)->Is(Type::Signed32())); | 559 NodeProperties::GetType(node)->Is(Type::Signed32())); |
560 } | 560 } |
561 | 561 |
562 bool CanLowerToWord32AdditiveBinop(Node* node, Truncation use) { | 562 bool CanLowerToInt32AdditiveBinop(Node* node, Truncation use) { |
| 563 // It is safe to lower to word32 operation if: |
| 564 // - the inputs are safe integers (so the low bits are not discarded), and |
| 565 // - the uses can only observe the lowest 32 bits or they can recover the |
| 566 // the value from the type. |
| 567 // TODO(jarin): we could support the uint32 case here, but that would |
| 568 // require setting kTypeUint32 as the output type. Eventually, we will want |
| 569 // to use only the big types, then this should work automatically. |
563 return BothInputsAre(node, safe_int_additive_range_) && | 570 return BothInputsAre(node, safe_int_additive_range_) && |
564 use.TruncatesToWord32(); | 571 (use.TruncatesToWord32() || |
| 572 NodeProperties::GetType(node)->Is(Type::Signed32())); |
565 } | 573 } |
566 | 574 |
567 // Dispatching routine for visiting the node {node} with the usage {use}. | 575 // Dispatching routine for visiting the node {node} with the usage {use}. |
568 // Depending on the operator, propagate new usage info to the inputs. | 576 // Depending on the operator, propagate new usage info to the inputs. |
569 void VisitNode(Node* node, Truncation truncation, | 577 void VisitNode(Node* node, Truncation truncation, |
570 SimplifiedLowering* lowering) { | 578 SimplifiedLowering* lowering) { |
571 switch (node->opcode()) { | 579 switch (node->opcode()) { |
572 //------------------------------------------------------------------ | 580 //------------------------------------------------------------------ |
573 // Common operators. | 581 // Common operators. |
574 //------------------------------------------------------------------ | 582 //------------------------------------------------------------------ |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 // => Float64Cmp | 690 // => Float64Cmp |
683 VisitFloat64Cmp(node); | 691 VisitFloat64Cmp(node); |
684 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); | 692 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); |
685 } | 693 } |
686 break; | 694 break; |
687 } | 695 } |
688 case IrOpcode::kNumberAdd: | 696 case IrOpcode::kNumberAdd: |
689 case IrOpcode::kNumberSubtract: { | 697 case IrOpcode::kNumberSubtract: { |
690 // Add and subtract reduce to Int32Add/Sub if the inputs | 698 // Add and subtract reduce to Int32Add/Sub if the inputs |
691 // are already integers and all uses are truncating. | 699 // are already integers and all uses are truncating. |
692 if (CanLowerToWord32AdditiveBinop(node, truncation)) { | 700 if (CanLowerToInt32AdditiveBinop(node, truncation)) { |
693 // => signed Int32Add/Sub | 701 // => signed Int32Add/Sub |
694 VisitInt32Binop(node); | 702 VisitInt32Binop(node); |
695 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); | 703 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); |
696 } else { | 704 } else { |
697 // => Float64Add/Sub | 705 // => Float64Add/Sub |
698 VisitFloat64Binop(node); | 706 VisitFloat64Binop(node); |
699 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); | 707 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); |
700 } | 708 } |
701 break; | 709 break; |
702 } | 710 } |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 ReplaceEffectUses(node, comparison); | 1605 ReplaceEffectUses(node, comparison); |
1598 node->ReplaceInput(0, comparison); | 1606 node->ReplaceInput(0, comparison); |
1599 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); | 1607 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); |
1600 node->TrimInputCount(2); | 1608 node->TrimInputCount(2); |
1601 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); | 1609 NodeProperties::ChangeOp(node, machine()->IntLessThanOrEqual()); |
1602 } | 1610 } |
1603 | 1611 |
1604 } // namespace compiler | 1612 } // namespace compiler |
1605 } // namespace internal | 1613 } // namespace internal |
1606 } // namespace v8 | 1614 } // namespace v8 |
OLD | NEW |