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

Unified Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 1284233003: dart2js CPS: Fix a bug in commuting binary operations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Merge tip of tree. Created 5 years, 4 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
diff --git a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
index 3fa61dd22b4d1e5d8f4f58f26164fa4398048d87..583c81b544e85354fc99ddb0b3bd131c9ddb0916 100644
--- a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
+++ b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
@@ -387,7 +387,7 @@ class StatementRewriter extends Transformer implements Pass {
}
/// Attempts to propagate an assignment in an expression statement.
- ///
+ ///
/// Returns a callback to be invoked after the sucessor statement has
/// been processed.
Function processExpressionStatement(ExpressionStatement stmt) {
@@ -405,7 +405,7 @@ class StatementRewriter extends Transformer implements Pass {
return (Statement next) {
popDominatingAssignment(leftHand);
if (assign.variable.readCount > 0) {
- // The assignment could not be propagated into the successor,
+ // The assignment could not be propagated into the successor,
// either because it [hasUnsafeVariableUse] or because the
// use is outside the current try block, and we do not currently
// support constant propagation out of a try block.
@@ -841,15 +841,18 @@ class StatementRewriter extends Transformer implements Pass {
BuiltinOperator commuted = commuteBinaryOperator(node.operator);
if (commuted != null) {
assert(node.arguments.length == 2); // Only binary operators can commute.
- VariableUse arg1 = node.arguments[0];
- VariableUse arg2 = node.arguments[1];
- if (propagatableVariable == arg1.variable &&
- propagatableVariable != arg2.variable &&
- !constantEnvironment.containsKey(arg2.variable)) {
- // An assignment can be propagated if we commute the operator.
- node.operator = commuted;
- node.arguments[0] = arg2;
- node.arguments[1] = arg1;
+ Expression left = node.arguments[0];
+ if (left is VariableUse && propagatableVariable == left.variable) {
+ Expression right = node.arguments[1];
+ if (right is This ||
+ (right is VariableUse &&
+ propagatableVariable != right.variable &&
+ !constantEnvironment.containsKey(right.variable))) {
+ // An assignment can be propagated if we commute the operator.
+ node.operator = commuted;
+ node.arguments[0] = right;
+ node.arguments[1] = left;
+ }
}
}
_rewriteList(node.arguments);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698