Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: src/compiler/typed-optimization.cc

Issue 2614663002: [turbofan] Recognize and optimize flooring integer division. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/typed-optimization.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/typed-optimization.cc
diff --git a/src/compiler/typed-optimization.cc b/src/compiler/typed-optimization.cc
index 5ebc390c8bc6a1d5f2c7bc3807211ebb88dba30c..8149a1bee4492903d33cacaffe62ad098e633db9 100644
--- a/src/compiler/typed-optimization.cc
+++ b/src/compiler/typed-optimization.cc
@@ -83,10 +83,11 @@ Reduction TypedOptimization::Reduce(Node* node) {
case IrOpcode::kLoadField:
return ReduceLoadField(node);
case IrOpcode::kNumberCeil:
- case IrOpcode::kNumberFloor:
case IrOpcode::kNumberRound:
case IrOpcode::kNumberTrunc:
return ReduceNumberRoundop(node);
+ case IrOpcode::kNumberFloor:
+ return ReduceNumberFloor(node);
case IrOpcode::kNumberToUint8Clamped:
return ReduceNumberToUint8Clamped(node);
case IrOpcode::kPhi:
@@ -185,6 +186,40 @@ Reduction TypedOptimization::ReduceLoadField(Node* node) {
return NoChange();
}
+Reduction TypedOptimization::ReduceNumberFloor(Node* node) {
+ Node* const input = NodeProperties::GetValueInput(node, 0);
+ Type* const input_type = NodeProperties::GetType(input);
+ if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) {
+ return Replace(input);
+ }
+ if (input_type->Is(Type::PlainNumber()) &&
+ input->opcode() == IrOpcode::kNumberDivide) {
+ Node* const lhs = NodeProperties::GetValueInput(input, 0);
+ Type* const lhs_type = NodeProperties::GetType(lhs);
+ Node* const rhs = NodeProperties::GetValueInput(input, 1);
+ Type* const rhs_type = NodeProperties::GetType(rhs);
+ if (lhs_type->Is(Type::Unsigned32()) && rhs_type->Is(Type::Unsigned32())) {
+ // We can replace
+ //
+ // NumberFloor(NumberDivide(lhs: unsigned32,
+ // rhs: unsigned32)): plain-number
+ //
+ // with
+ //
+ // NumberToUint32(NumberDivide(lhs, rhs))
+ //
+ // and just smash the type of the {lhs} on the {node},
+ // as the truncated result must be in the same range as
+ // {lhs} since {rhs} cannot be less than 1 (due to the
+ // plain-number type constraint on the {node}).
+ NodeProperties::ChangeOp(node, simplified()->NumberToUint32());
+ NodeProperties::SetType(node, lhs_type);
+ return Changed(node);
+ }
+ }
+ return NoChange();
+}
+
Reduction TypedOptimization::ReduceNumberRoundop(Node* node) {
Node* const input = NodeProperties::GetValueInput(node, 0);
Type* const input_type = NodeProperties::GetType(input);
« no previous file with comments | « src/compiler/typed-optimization.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698