From 28f859a9654585e606f445985d5c618308a5f61c Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 22 Nov 2015 07:37:13 +0000 Subject: compile.c: optimize useless branches * compile.c (iseq_peephole_optimize): eliminate always/never branches after a literal object and when the value is used after the branch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ compile.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3128441fcf..7921ccbf62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Nov 22 16:37:10 2015 Nobuyoshi Nakada + + * compile.c (iseq_peephole_optimize): eliminate always/never + branches after a literal object and when the value is used after + the branch. + Sun Nov 22 01:23:43 2015 Naohisa Goto * configure.in: Add -D_XOPEN_SOURCE=500 (or 600 or 700) on Solaris diff --git a/compile.c b/compile.c index c199424ca1..54cf643f48 100644 --- a/compile.c +++ b/compile.c @@ -2053,8 +2053,18 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal * => * jump L1 * + * putstring ".." + * dup + * if L1 + * => + * putstring ".." + * jump L1 + * */ int cond; + if (prev_dup && pobj->link.prev->type == ISEQ_ELEMENT_INSN) { + pobj = (INSN *)pobj->link.prev; + } if (pobj->insn_id == BIN(putobject)) { cond = (iobj->insn_id == BIN(branchif) ? OPERAND_AT(pobj, 0) != Qfalse : @@ -2069,7 +2079,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal cond = iobj->insn_id != BIN(branchif); } else break; - REMOVE_ELEM(&pobj->link); + REMOVE_ELEM(iobj->link.prev); if (cond) { iobj->insn_id = BIN(jump); goto again; -- cgit v1.2.3