scmno****@osdn*****
scmno****@osdn*****
Sat Jun 23 04:18:45 JST 2018
changeset 040ec1386e73 in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=040ec1386e73 user: Agustina Arzille <avarz****@riseu*****> date: Fri Jun 22 16:18:36 2018 -0300 description: Explain label fixing optimization diffstat: compiler.cpp | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diffs (39 lines): diff -r c7b157951a94 -r 040ec1386e73 compiler.cpp --- a/compiler.cpp Fri Jun 22 11:37:21 2018 -0300 +++ b/compiler.cpp Fri Jun 22 16:18:36 2018 -0300 @@ -359,7 +359,34 @@ int ix = this->last_idx (); if (ix >= 0 && (cv[ix] == OPX_(LOADT) || cv[ix] == OPX_(LOADNIL))) { - cv.erase (cv.begin () + ix); + if (ix >= 2 && cv[ix - 2] == OPX_(LABEL)) + { /* Common pattern: + * jmp L1 + * ... + * jmp L2 + * L1: loadnil + * L2: pop + * ... + * + * Such bytecode can be generated by non-tail 'if' forms + * without an 'else' clause. We optimize by rearranging + * the label L1 to point forward and avoid the redundant + * loadnil+pop instruction: + * + * jmp L1 + * ... + * pop + * L1: ... + */ + int lbl = as_int (cv[ix - 1]); + cv.erase (cv.begin () + ix - 2, cv.begin () + ix + 1); + this->emit (OPX_(POP)); + this->mark_label (lbl); + } + else + // Eliminate the loadK+pop sequence. + cv.erase (cv.begin () + ix); + return; } }