Skip to content

Commit

Permalink
[vm/bytecode] Optimize comparisons with null
Browse files Browse the repository at this point in the history
BinaryTrees(RunTime): 72191.33325 us. -> 68058.06103333333 us.
(linux/x64, bytecode compiler enabled)

Issue: dart-lang/sdk#36429

Change-Id: Ie5344d874f6b4afc5e8b6516fc6283d83963f17f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115601
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
  • Loading branch information
alexmarkov authored and commit-bot@chromium.org committed Sep 5, 2019
1 parent 16a4c0d commit 4fbd758
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 23 additions & 0 deletions pkg/vm/lib/bytecode/gen_bytecode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,29 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
}
return;
}
if (condition is MethodInvocation &&
condition.name.name == '==' &&
(condition.receiver is NullLiteral ||
condition.arguments.positional.single is NullLiteral)) {
if (condition.receiver is NullLiteral) {
_generateNode(condition.arguments.positional.single);
} else {
_generateNode(condition.receiver);
}
if (options.emitDebuggerStops &&
condition.fileOffset != TreeNode.noOffset) {
final savedSourcePosition = asm.currentSourcePosition;
_recordSourcePosition(condition.fileOffset);
asm.emitDebugCheck();
asm.currentSourcePosition = savedSourcePosition;
}
if (value) {
asm.emitJumpIfNull(dest);
} else {
asm.emitJumpIfNotNull(dest);
}
return;
}
bool negated = _genCondition(condition);
if (value) {
_genJumpIfTrue(negated, dest);
Expand Down
9 changes: 3 additions & 6 deletions pkg/vm/testcases/bytecode/bootstrapping.dart.expect
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ Bytecode {
Entry 2
CheckStack 0
LoadStatic CP#0
EqualsNull
JumpIfFalse L1
JumpIfNotNull L1
LoadStatic CP#1
DirectCall CP#2, 1
StoreLocal r1
Expand Down Expand Up @@ -383,8 +382,7 @@ Bytecode {
Entry 2
CheckStack 0
LoadStatic CP#0
EqualsNull
JumpIfFalse L1
JumpIfNotNull L1
Allocate CP#1
StoreLocal r1
Push r1
Expand Down Expand Up @@ -583,8 +581,7 @@ Bytecode {
Entry 1
CheckStack 0
LoadStatic CP#0
EqualsNull
JumpIfFalse L1
JumpIfNotNull L1
LoadStatic CP#1
EqualsNull
BooleanNegateTOS
Expand Down

0 comments on commit 4fbd758

Please sign in to comment.