ruby-changes:40554
From: nobu <ko1@a...>
Date: Wed, 18 Nov 2015 11:32:25 +0900 (JST)
Subject: [ruby-changes:40554] nobu:r52633 (trunk): compile.c: optimize useless branches
nobu 2015-11-18 11:32:17 +0900 (Wed, 18 Nov 2015) New Revision: 52633 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52633 Log: compile.c: optimize useless branches * compile.c (iseq_peephole_optimize): eliminate always/never branches after a literal object. this sequence typically appears by defined? operator for a method call on a local variable. Modified files: trunk/ChangeLog trunk/compile.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52632) +++ ChangeLog (revision 52633) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Nov 18 11:32:15 2015 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_peephole_optimize): eliminate always/never + branches after a literal object. this sequence typically + appears by defined? operator for a method call on a local + variable. + Wed Nov 18 10:33:06 2015 NAKAMURA Usaku <usa@r...> * ext/socket/ancdata.c (bsock_recvmsg_internal): stretch the buffer size Index: compile.c =================================================================== --- compile.c (revision 52632) +++ compile.c (revision 52633) @@ -2031,6 +2031,33 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2031 */ replace_destination(iobj, nobj); } + else if (pobj) { + int cond; + if (pobj->insn_id == BIN(putobject)) { + cond = (iobj->insn_id == BIN(branchif) ? + OPERAND_AT(pobj, 0) != Qfalse : + iobj->insn_id == BIN(branchunless) ? + OPERAND_AT(pobj, 0) == Qfalse : + FALSE); + } + else if (pobj->insn_id == BIN(putstring)) { + cond = iobj->insn_id == BIN(branchif); + } + else if (pobj->insn_id == BIN(putnil)) { + cond = iobj->insn_id != BIN(branchif); + } + else break; + REMOVE_ELEM(&pobj->link); + if (cond) { + iobj->insn_id = BIN(jump); + goto again; + } + else { + unref_destination(iobj); + REMOVE_ELEM(&iobj->link); + } + break; + } else break; nobj = (INSN *)get_destination_insn(nobj); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/