[前][次][番号順一覧][スレッド一覧]

ruby-changes:40631

From: nobu <ko1@a...>
Date: Sun, 22 Nov 2015 16:37:26 +0900 (JST)
Subject: [ruby-changes:40631] nobu:r52710 (trunk): compile.c: optimize useless branches

nobu	2015-11-22 16:37:13 +0900 (Sun, 22 Nov 2015)

  New Revision: 52710

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52710

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52709)
+++ ChangeLog	(revision 52710)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Nov 22 16:37:10 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <ngotogenome@g...>
 
 	* configure.in: Add -D_XOPEN_SOURCE=500 (or 600 or 700) on Solaris
Index: compile.c
===================================================================
--- compile.c	(revision 52709)
+++ compile.c	(revision 52710)
@@ -2053,8 +2053,18 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2053
 		 * =>
 		 *   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, https://github.com/ruby/ruby/blob/trunk/compile.c#L2079
 		    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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]