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

ruby-changes:46700

From: nobu <ko1@a...>
Date: Sat, 20 May 2017 20:41:05 +0900 (JST)
Subject: [ruby-changes:46700] nobu:r58815 (trunk): compile.c: optimize branches

nobu	2017-05-20 20:40:57 +0900 (Sat, 20 May 2017)

  New Revision: 58815

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

  Log:
    compile.c: optimize branches
    
    * compile.c (compile_branch_condition, iseq_compile_each0):
      eliminate unreachable branches in NODE_IF.

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 58814)
+++ compile.c	(revision 58815)
@@ -2909,6 +2909,7 @@ compile_branch_condition(rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/compile.c#L2909
 	    LABEL *label = NEW_LABEL(nd_line(cond));
 	    CHECK(compile_branch_condition(iseq, ret, cond->nd_1st, label,
 					   else_label));
+	    if (!label->refcnt) break;
 	    ADD_LABEL(ret, label);
 	    cond = cond->nd_2nd;
 	    goto again;
@@ -2918,6 +2919,7 @@ compile_branch_condition(rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/compile.c#L2919
 	    LABEL *label = NEW_LABEL(nd_line(cond));
 	    CHECK(compile_branch_condition(iseq, ret, cond->nd_1st, then_label,
 					   label));
+	    if (!label->refcnt) break;
 	    ADD_LABEL(ret, label);
 	    cond = cond->nd_2nd;
 	    goto again;
@@ -4250,7 +4252,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L4252
 	INIT_ANCHOR(else_seq);
 	then_label = NEW_LABEL(line);
 	else_label = NEW_LABEL(line);
-	end_label = NEW_LABEL(line);
+	end_label = 0;
 
 	compile_branch_condition(iseq, cond_seq, node->nd_cond,
 				 then_label, else_label);
@@ -4259,14 +4261,21 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L4261
 
 	ADD_SEQ(ret, cond_seq);
 
-	ADD_LABEL(ret, then_label);
-	ADD_SEQ(ret, then_seq);
-	ADD_INSNL(ret, line, jump, end_label);
+	if (then_label->refcnt) {
+	    ADD_LABEL(ret, then_label);
+	    ADD_SEQ(ret, then_seq);
+	    end_label = NEW_LABEL(line);
+	    ADD_INSNL(ret, line, jump, end_label);
+	}
 
-	ADD_LABEL(ret, else_label);
-	ADD_SEQ(ret, else_seq);
+	if (else_label->refcnt) {
+	    ADD_LABEL(ret, else_label);
+	    ADD_SEQ(ret, else_seq);
+	}
 
-	ADD_LABEL(ret, end_label);
+	if (end_label) {
+	    ADD_LABEL(ret, end_label);
+	}
 
 	break;
       }

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

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