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

Unified Diff: src/compiler/control-reducer.cc

Issue 1057843002: [turbofan] Improve branch folding over phis and ranges. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | test/unittests/compiler/control-reducer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/control-reducer.cc
diff --git a/src/compiler/control-reducer.cc b/src/compiler/control-reducer.cc
index 25a680d62a544c5fcd5999bb5bb4a30dd3f2a860..238b510671d7e79af7a128fae9626193a283790a 100644
--- a/src/compiler/control-reducer.cc
+++ b/src/compiler/control-reducer.cc
@@ -433,7 +433,7 @@ class ControlReducerImpl {
}
// Try to statically fold a condition.
- Decision DecideCondition(Node* cond) {
+ Decision DecideCondition(Node* cond, bool recurse = true) {
switch (cond->opcode()) {
case IrOpcode::kInt32Constant:
return Int32Matcher(cond).Is(0) ? kFalse : kTrue;
@@ -444,14 +444,29 @@ class ControlReducerImpl {
case IrOpcode::kHeapConstant: {
Handle<Object> object =
HeapObjectMatcher<Object>(cond).Value().handle();
- if (object->IsTrue()) return kTrue;
- if (object->IsFalse()) return kFalse;
- // TODO(turbofan): decide more conditions for heap constants.
- break;
+ return object->BooleanValue() ? kTrue : kFalse;
+ }
+ case IrOpcode::kPhi: {
+ if (!recurse) return kUnknown; // Only go one level deep checking phis.
+ Decision result = kUnknown;
+ // Check if all inputs to a phi result in the same decision.
+ for (int i = cond->op()->ValueInputCount() - 1; i >= 0; i--) {
+ // Recurse only one level, since phis can be involved in cycles.
+ Decision decision = DecideCondition(cond->InputAt(i), false);
+ if (decision == kUnknown) return kUnknown;
+ if (result == kUnknown) result = decision;
+ if (result != decision) return kUnknown;
+ }
+ return result;
}
default:
break;
}
+ if (NodeProperties::IsTyped(cond)) {
+ // If the node has a range type, check whether the range excludes 0.
+ Type* type = NodeProperties::GetBounds(cond).upper;
+ if (type->IsRange() && (type->Min() > 0 || type->Max() < 0)) return kTrue;
+ }
return kUnknown;
}
« no previous file with comments | « no previous file | test/unittests/compiler/control-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698