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

Unified Diff: pkg/compiler/lib/src/cps_ir/type_propagation.dart

Issue 1590523004: Revert "dart2js cps: Avoid comparing boolean values to boolean constants." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 | « 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/cps_ir/type_propagation.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
index e81eb419d7ddaea1de769ee823b3b3ae37dcdbe5..40137c33a47f4527f4c770fd004a7cf76e05bafb 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -1049,16 +1049,6 @@ class TransformingVisitor extends DeepRecursiveVisitor {
push(invoke);
return;
}
-
- // Shortcut negation to help simplify control flow. The tree IR will insert
- // a negation again if that's useful.
- if (condition is ApplyBuiltinOperator &&
- condition.operator == BuiltinOperator.IsFalsy) {
- node.condition.changeTo(condition.arguments.single.definition);
- node.trueContinuation.changeTo(falseCont);
- node.falseContinuation.changeTo(trueCont);
- return;
- }
}
void visitInvokeContinuation(InvokeContinuation node) {
@@ -2003,7 +1993,7 @@ class TransformingVisitor extends DeepRecursiveVisitor {
// Nothing happens. The primitive remains as it is.
//
- visitApplyBuiltinOperator(ApplyBuiltinOperator node) {
+ void visitApplyBuiltinOperator(ApplyBuiltinOperator node) {
ast.DartString getString(AbstractConstantValue value) {
StringConstantValue constant = value.constant;
return constant.primitiveValue;
@@ -2063,70 +2053,42 @@ class TransformingVisitor extends DeepRecursiveVisitor {
Primitive rightArg = node.arguments[1].definition;
AbstractConstantValue left = getValue(leftArg);
AbstractConstantValue right = getValue(rightArg);
- BuiltinOperator newOperator;
- if (left.isNullConstant || right.isNullConstant) {
+ if (lattice.isDefinitelyBool(left) &&
+ right.isConstant &&
+ right.constant.isTrue) {
+ // Replace identical(x, true) by x when x is known to be a boolean.
+ // Note that this is not safe if x is null, because the value might
+ // not be used as a condition.
+ node.replaceUsesWith(leftArg);
+ } else if (lattice.isDefinitelyBool(right) &&
+ left.isConstant &&
+ left.constant.isTrue) {
+ node.replaceUsesWith(rightArg);
+ } else if (left.isNullConstant || right.isNullConstant) {
// Use `==` for comparing against null, so JS undefined and JS null
// are considered equal.
- newOperator = BuiltinOperator.LooseEq;
+ node.operator = BuiltinOperator.LooseEq;
} else if (!left.isNullable || !right.isNullable) {
// If at most one operand can be Dart null, we can use `===`.
// This is not safe when we might compare JS null and JS undefined.
- newOperator = BuiltinOperator.StrictEq;
+ node.operator = BuiltinOperator.StrictEq;
} else if (lattice.isDefinitelyNum(left, allowNull: true) &&
lattice.isDefinitelyNum(right, allowNull: true)) {
// If both operands can be null, but otherwise are of the same type,
// we can use `==` for comparison.
// This is not safe e.g. for comparing strings against numbers.
- newOperator = BuiltinOperator.LooseEq;
+ node.operator = BuiltinOperator.LooseEq;
} else if (lattice.isDefinitelyString(left, allowNull: true) &&
lattice.isDefinitelyString(right, allowNull: true)) {
- newOperator = BuiltinOperator.LooseEq;
+ node.operator = BuiltinOperator.LooseEq;
} else if (lattice.isDefinitelyBool(left, allowNull: true) &&
lattice.isDefinitelyBool(right, allowNull: true)) {
- newOperator = BuiltinOperator.LooseEq;
- }
- if (newOperator != null) {
- return new ApplyBuiltinOperator(newOperator,
- node.arguments.map((ref) => ref.definition).toList(),
- node.sourceInformation);
- }
- break;
-
- case BuiltinOperator.StrictEq:
- case BuiltinOperator.LooseEq:
- case BuiltinOperator.StrictNeq:
- case BuiltinOperator.LooseNeq:
- bool negated =
- node.operator == BuiltinOperator.StrictNeq ||
- node.operator == BuiltinOperator.LooseNeq;
- for (int firstIndex in [0, 1]) {
- int secondIndex = 1 - firstIndex;
- Primitive firstArg = node.arguments[firstIndex].definition;
- Primitive secondArg = node.arguments[secondIndex].definition;
- AbstractConstantValue first = getValue(firstArg);
- if (!lattice.isDefinitelyBool(first)) continue;
- AbstractConstantValue second = getValue(secondArg);
- if (!second.isConstant || !second.constant.isBool) continue;
- bool isTrueConstant = second.constant.isTrue;
- if (isTrueConstant == !negated) {
- // (x === true) ==> x
- // (x !== false) ==> x
- node.replaceUsesWith(firstArg);
- return null;
- } else {
- // (x === false) ==> !x
- // (x !== true) ==> !x
- return new ApplyBuiltinOperator(
- BuiltinOperator.IsFalsy,
- [firstArg],
- node.sourceInformation);
- }
+ node.operator = BuiltinOperator.LooseEq;
}
break;
default:
}
- return null;
}
void visitApplyBuiltinMethod(ApplyBuiltinMethod node) {
« 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