ruby-changes:47539
From: nobu <ko1@a...>
Date: Fri, 25 Aug 2017 12:34:01 +0900 (JST)
Subject: [ruby-changes:47539] nobu:r59655 (trunk): compile.c: useless jump elimination
nobu 2017-08-25 12:33:32 +0900 (Fri, 25 Aug 2017) New Revision: 59655 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59655 Log: compile.c: useless jump elimination * compile.c (iseq_peephole_optimize): eliminate useless if/unless just before jump. Modified files: trunk/compile.c Index: compile.c =================================================================== --- compile.c (revision 59654) +++ compile.c (revision 59655) @@ -866,7 +866,6 @@ INSERT_ELEM_PREV(LINK_ELEMENT *elem1, LI https://github.com/ruby/ruby/blob/trunk/compile.c#L866 } } -#if 0 /* * elemX, elem1, elemY => elemX, elem2, elemY */ @@ -882,7 +881,6 @@ REPLACE_ELEM(LINK_ELEMENT *elem1, LINK_E https://github.com/ruby/ruby/blob/trunk/compile.c#L881 elem1->next->prev = elem2; } } -#endif static void REMOVE_ELEM(LINK_ELEMENT *elem) @@ -2211,7 +2209,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2209 else if ((piobj = (INSN *)get_prev_insn(iobj)) != 0 && (IS_INSN_ID(piobj, branchif) || IS_INSN_ID(piobj, branchunless))) { - if (niobj == (INSN *)get_destination_insn(piobj)) { + INSN *pdiobj = (INSN *)get_destination_insn(piobj); + if (niobj == pdiobj) { /* * useless jump elimination (if/unless destination): * if L1 @@ -2231,6 +2230,24 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2230 replace_destination(piobj, iobj); REMOVE_ELEM(&iobj->link); } + else if (diobj == pdiobj) { + /* + * useless jump elimination (if/unless before jump): + * L1: + * ... + * if L1 + * jump L1 + * + * ==> + * L1: + * ... + * pop + * jump L1 + */ + INSN *popiobj = new_insn_core(iseq, iobj->line_no, + BIN(pop), 0, 0); + REPLACE_ELEM(&piobj->link, &popiobj->link); + } } else if (remove_unreachable_chunk(iseq, iobj->link.next)) { goto again; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/