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

Unified Diff: lib/compiler/implementation/ssa/optimize.dart

Issue 10174040: Better constant fold identity checks. (100 bytes saved on swarm, yeah! :)) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
Index: lib/compiler/implementation/ssa/optimize.dart
===================================================================
--- lib/compiler/implementation/ssa/optimize.dart (revision 6988)
+++ lib/compiler/implementation/ssa/optimize.dart (working copy)
@@ -293,10 +293,60 @@
return node;
}
+ HInstruction handleIdentityCheck(HInvokeBinary node) {
Lasse Reichstein Nielsen 2012/04/26 07:24:02 With the new == semantics (which we haven't implem
ngeoffray 2012/04/26 09:25:19 True. Let's wait until we start implementing the n
+ HInstruction left = node.left;
+ HInstruction right = node.right;
+ if (left.propagatedType.union(right.propagatedType) === HType.CONFLICTING) {
floitsch 2012/04/26 08:31:16 This should be intersection, except for numbers. T
ngeoffray 2012/04/26 09:25:19 I used union because I was mostly thinking of the
+ return graph.addConstantBool(false);
floitsch 2012/04/26 08:31:16 I don't think this is correct: A phi with inputs i
ngeoffray 2012/04/26 09:25:19 I'm not sure I understand how this relates to the
ngeoffray 2012/04/26 10:09:53 Actually, it looks like a phi never gets a conflic
+ }
+
+ if (left.isConstantBoolean() && right.isBoolean()) {
+ HConstant constant = left;
+ if (constant.constant.isTrue()) {
+ return right;
+ } else {
+ return new HNot(right);
+ }
+ }
+
+ if (right.isConstantBoolean() && left.isBoolean()) {
+ HConstant constant = right;
+ if (constant.constant.isTrue()) {
+ return left;
+ } else {
+ return new HNot(left);
+ }
+ }
+
+ return null;
+ }
+
+ HInstruction visitIdentity(HIdentity node) {
+ HInstruction newInstruction = handleIdentityCheck(node);
+ return newInstruction === null ? super.visitIdentity(node) : newInstruction;
+ }
+
+ HInstruction foldBuiltinEqualsCheck(HEquals node) {
+ // TODO(floitsch): cache interceptors.
+ HInstruction newInstruction = handleIdentityCheck(node);
+ if (newInstruction === null) {
+ HStatic target = new HStatic(
+ compiler.builder.interceptors.getTripleEqualsInterceptor());
+ node.block.addBefore(node, target);
+ return new HIdentity(target, node.left, node.right);
+ } else {
+ return newInstruction;
+ }
+ }
+
HInstruction visitEquals(HEquals node) {
HInstruction left = node.left;
HInstruction right = node.right;
+ if (node.builtin) {
+ return foldBuiltinEqualsCheck(node);
+ }
+
if (left.isConstant() && right.isConstant()) {
return visitInvokeBinary(node);
}
@@ -314,15 +364,10 @@
} else {
// We can just emit an identity check because the type does
// not implement operator=.
- // TODO(floitsch): cache interceptors.
- HStatic target = new HStatic(
- compiler.builder.interceptors.getTripleEqualsInterceptor());
- node.block.addBefore(node, target);
- return new HIdentity(target, left, right);
+ return foldBuiltinEqualsCheck(node);
}
}
-
if (right.isConstantNull()) {
if (left.propagatedType.isUseful()) {
return graph.addConstantBool(false);
« lib/compiler/implementation/ssa/nodes.dart ('K') | « lib/compiler/implementation/ssa/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698