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

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

Issue 1583993005: dart2js cps: Improve constant folding of equality operators. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update unit test after rebasing 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 | tests/co19/co19-dart2js.status » ('j') | 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..56f02ab277951afcab9c4bd7c62f6c97d0e62ef1 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -2662,37 +2662,34 @@ class TypePropagationVisitor implements Visitor {
case BuiltinOperator.Identical:
case BuiltinOperator.StrictEq:
+ case BuiltinOperator.StrictNeq:
case BuiltinOperator.LooseEq:
- AbstractConstantValue leftConst =
- getValue(node.arguments[0].definition);
- AbstractConstantValue rightConst =
- getValue(node.arguments[1].definition);
- ConstantValue leftValue = leftConst.constant;
- ConstantValue rightValue = rightConst.constant;
- if (leftConst.isNothing || rightConst.isNothing) {
+ case BuiltinOperator.LooseNeq:
+ bool negated =
+ node.operator == BuiltinOperator.StrictNeq ||
+ node.operator == BuiltinOperator.LooseNeq;
+ AbstractConstantValue left = getValue(node.arguments[0].definition);
+ AbstractConstantValue right = getValue(node.arguments[1].definition);
+ if (left.isNothing || right.isNothing) {
setValue(node, lattice.nothing);
- return; // And come back later.
- } else if (!leftConst.isConstant || !rightConst.isConstant) {
- TypeMask leftType = leftConst.type;
- TypeMask rightType = rightConst.type;
- if (typeSystem.areDisjoint(leftType, rightType)) {
- setValue(node,
- constantValue(new FalseConstantValue(), typeSystem.boolType));
- } else {
- setValue(node, nonConstant(typeSystem.boolType));
- }
return;
- } else if (leftValue.isPrimitive && rightValue.isPrimitive) {
- assert(leftConst.isConstant && rightConst.isConstant);
- PrimitiveConstantValue left = leftValue;
- PrimitiveConstantValue right = rightValue;
- // Should this be constantSystem.identity.fold(left, right)?
- ConstantValue result =
- new BoolConstantValue(left.primitiveValue == right.primitiveValue);
+ }
+ if (left.isConstant && right.isConstant) {
+ ConstantValue equal = lattice.constantSystem.identity.fold(
+ left.constant, right.constant);
+ if (equal != null && equal.isBool) {
+ ConstantValue result =
+ new BoolConstantValue(equal.isTrue == !negated);
+ setValue(node, constantValue(result, typeSystem.boolType));
+ return;
+ }
+ }
+ if (typeSystem.areDisjoint(left.type, right.type)) {
+ ConstantValue result = new BoolConstantValue(negated);
setValue(node, constantValue(result, typeSystem.boolType));
- } else {
- setValue(node, nonConstant(typeSystem.boolType));
+ return;
}
+ setValue(node, nonConstant(typeSystem.boolType));
break;
case BuiltinOperator.NumAdd:
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698