From 72f88ebcc16c29f8848174034b4b89ebd0ecb31e Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 22 Oct 2017 01:46:43 +0000 Subject: [PATCH] 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 --- compile.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compile.c b/compile.c index da75cfec5a..b605120a24 100644 --- a/compile.c +++ b/compile.c @@ -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); } } }