diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-22 01:46:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-22 01:46:43 +0000 |
commit | 72f88ebcc16c29f8848174034b4b89ebd0ecb31e (patch) | |
tree | 7059aeae2b1272a83a8c71a43bf165566820dffa /compile.c | |
parent | f644d3ef6789672fcae8b3da2e91655ad2cd736a (diff) |
compile.c: optimize local variable assignments
* compile.c (iseq_peephole_optimize): eliminate simple self
assignments of a local variable when the result is used.
follow-up of r60322.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -2597,12 +2597,16 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal } if (IS_INSN_ID(iobj, getlocal)) { - if (IS_NEXT_INSN_ID(&iobj->link, setlocal)) { - LINK_ELEMENT *set1 = iobj->link.next; + LINK_ELEMENT *niobj = &iobj->link; + if (IS_NEXT_INSN_ID(niobj, dup)) { + niobj = niobj->next; + } + if (IS_NEXT_INSN_ID(niobj, setlocal)) { + LINK_ELEMENT *set1 = niobj->next; if (OPERAND_AT(iobj, 0) == OPERAND_AT(set1, 0) && OPERAND_AT(iobj, 1) == OPERAND_AT(set1, 1)) { REMOVE_ELEM(set1); - REMOVE_ELEM(&iobj->link); + REMOVE_ELEM(niobj); } } } |