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

ruby-changes:56043

From: Yusuke <ko1@a...>
Date: Fri, 7 Jun 2019 14:47:18 +0900 (JST)
Subject: [ruby-changes:56043] Yusuke Endoh: a6a26e42b1 (trunk): compile.c: Partially revert r63870 which caused wrong optimization

https://git.ruby-lang.org/ruby.git/commit/?id=a6a26e42b1

From a6a26e42b15c46f117f4fce07a2050e9d727355d Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 7 Jun 2019 14:45:06 +0900
Subject: compile.c: Partially revert r63870 which caused wrong optimization

[Bug #15906]

diff --git a/compile.c b/compile.c
index 60cdb76..2021571 100644
--- a/compile.c
+++ b/compile.c
@@ -2735,7 +2735,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2735
             ELEM_INSERT_NEXT(&iobj->link, &pop->link);
 	    goto again;
 	}
-	else if ((piobj = (INSN *)get_prev_insn(iobj)) != 0 &&
+       else if (IS_INSN(iobj->link.prev) &&
+                 (piobj = (INSN *)iobj->link.prev) &&
 		 (IS_INSN_ID(piobj, branchif) ||
 		  IS_INSN_ID(piobj, branchunless))) {
 	    INSN *pdiobj = (INSN *)get_destination_insn(piobj);
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index d6649cc..cb65b3a 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -795,6 +795,21 @@ class TestRubyOptimization < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L795
     assert_equal(:ok, x.bug(:ok))
   end
 
+  def test_jump_elimination_with_optimized_out_block_2
+    x = Object.new
+    def x.bug
+      a = "aaa"
+      ok = :NG
+      if a == "bbb" || a == "ccc" then
+        a = a
+      else
+        ok = :ok
+      end
+      ok
+    end
+    assert_equal(:ok, x.bug)
+  end
+
   def test_peephole_jump_after_newarray
     i = 0
     %w(1) || 2 while (i += 1) < 100
-- 
cgit v0.10.2


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

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