Skip to content

Commit 4fbd758

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/bytecode] Optimize comparisons with null
BinaryTrees(RunTime): 72191.33325 us. -> 68058.06103333333 us. (linux/x64, bytecode compiler enabled) Issue: #36429 Change-Id: Ie5344d874f6b4afc5e8b6516fc6283d83963f17f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115601 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Régis Crelier <[email protected]>
1 parent 16a4c0d commit 4fbd758

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

pkg/vm/lib/bytecode/gen_bytecode.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,29 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
13661366
}
13671367
return;
13681368
}
1369+
if (condition is MethodInvocation &&
1370+
condition.name.name == '==' &&
1371+
(condition.receiver is NullLiteral ||
1372+
condition.arguments.positional.single is NullLiteral)) {
1373+
if (condition.receiver is NullLiteral) {
1374+
_generateNode(condition.arguments.positional.single);
1375+
} else {
1376+
_generateNode(condition.receiver);
1377+
}
1378+
if (options.emitDebuggerStops &&
1379+
condition.fileOffset != TreeNode.noOffset) {
1380+
final savedSourcePosition = asm.currentSourcePosition;
1381+
_recordSourcePosition(condition.fileOffset);
1382+
asm.emitDebugCheck();
1383+
asm.currentSourcePosition = savedSourcePosition;
1384+
}
1385+
if (value) {
1386+
asm.emitJumpIfNull(dest);
1387+
} else {
1388+
asm.emitJumpIfNotNull(dest);
1389+
}
1390+
return;
1391+
}
13691392
bool negated = _genCondition(condition);
13701393
if (value) {
13711394
_genJumpIfTrue(negated, dest);

pkg/vm/testcases/bytecode/bootstrapping.dart.expect

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ Bytecode {
210210
Entry 2
211211
CheckStack 0
212212
LoadStatic CP#0
213-
EqualsNull
214-
JumpIfFalse L1
213+
JumpIfNotNull L1
215214
LoadStatic CP#1
216215
DirectCall CP#2, 1
217216
StoreLocal r1
@@ -383,8 +382,7 @@ Bytecode {
383382
Entry 2
384383
CheckStack 0
385384
LoadStatic CP#0
386-
EqualsNull
387-
JumpIfFalse L1
385+
JumpIfNotNull L1
388386
Allocate CP#1
389387
StoreLocal r1
390388
Push r1
@@ -583,8 +581,7 @@ Bytecode {
583581
Entry 1
584582
CheckStack 0
585583
LoadStatic CP#0
586-
EqualsNull
587-
JumpIfFalse L1
584+
JumpIfNotNull L1
588585
LoadStatic CP#1
589586
EqualsNull
590587
BooleanNegateTOS

0 commit comments

Comments
 (0)