Skip to content

Commit 7f73340

Browse files
committed
Add a peephole optimization to remove "0 + VAR".
This pattern is generated on accessing the first element of an array.
1 parent 8a8714a commit 7f73340

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/compiler/peephole.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ class peephole
524524
del(3); del(2); del(1); del(0); i--;
525525
continue;
526526
}
527+
// TOK_NUM / 0 / TOK_ADD_VAR -> TOK_VAR_LOAD
528+
if( mtok(0,TOK_NUM) && mword(1) && val(1) == 0 &&
529+
mtok(2,TOK_ADD_VAR) )
530+
{
531+
del(1); del(0); set_tok(0, TOK_VAR_LOAD); i--;
532+
continue;
533+
}
527534
// TOK_PUSH / TOK_NUM / 0 / TOK_SUB -> -
528535
if( mtok(0,TOK_PUSH) && mtok(1,TOK_NUM) && mword(2) &&
529536
val(2) == 0 && mtok(3,TOK_SUB) )

0 commit comments

Comments
 (0)