ruby-changes:52681
From: nagachika <ko1@a...>
Date: Mon, 1 Oct 2018 21:02:23 +0900 (JST)
Subject: [ruby-changes:52681] nagachika:r64893 (ruby_2_5): merge revision(s) 63868, 63870: [Backport #14897]
nagachika 2018-10-01 21:02:17 +0900 (Mon, 01 Oct 2018) New Revision: 64893 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64893 Log: merge revision(s) 63868,63870: [Backport #14897] Fix a bug of peephole optimization ``` if L1 L0: jump L2 L1: ... L2: ``` was wrongly optimized to: ``` unless L2 L0: L1: ... L2: ``` To make it conservative, this optimization is now disabled when there is any label between `if` and `jump` instructions. Fixes [Bug #14897]. compile.c: remove unreachable jump only * compile.c (iseq_peephole_optimize): remove unreachable jump instruction only. if it is labeled and referred from other instructions, it is reachable and must not be removed. [ruby-core:87830] [Bug #14897] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/bootstraptest/test_flow.rb branches/ruby_2_5/compile.c branches/ruby_2_5/test/ruby/test_optimization.rb branches/ruby_2_5/version.h Index: ruby_2_5/test/ruby/test_optimization.rb =================================================================== --- ruby_2_5/test/ruby/test_optimization.rb (revision 64892) +++ ruby_2_5/test/ruby/test_optimization.rb (revision 64893) @@ -730,4 +730,17 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_optimization.rb#L730 tap {true || tap {}} end; end + + def test_jump_elimination_with_optimized_out_block + x = Object.new + def x.bug(obj) + if obj || obj + obj = obj + else + raise "[ruby-core:87830] [Bug #14897]" + end + obj + end + assert_equal(:ok, x.bug(:ok)) + end end Index: ruby_2_5/compile.c =================================================================== --- ruby_2_5/compile.c (revision 64892) +++ ruby_2_5/compile.c (revision 64893) @@ -2469,6 +2469,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ruby_2_5/compile.c#L2469 IS_INSN_ID(piobj, branchunless))) { INSN *pdiobj = (INSN *)get_destination_insn(piobj); if (niobj == pdiobj) { + int refcnt = IS_LABEL(piobj->link.next) ? + ((LABEL *)piobj->link.next)->refcnt : 0; /* * useless jump elimination (if/unless destination): * if L1 @@ -2486,7 +2488,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ruby_2_5/compile.c#L2488 piobj->insn_id = (IS_INSN_ID(piobj, branchif)) ? BIN(branchunless) : BIN(branchif); replace_destination(piobj, iobj); - ELEM_REMOVE(&iobj->link); + if (refcnt <= 1) { + ELEM_REMOVE(&iobj->link); + } + else { + /* TODO: replace other branch destinations too */ + } return COMPILE_OK; } else if (diobj == pdiobj) { Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 64892) +++ ruby_2_5/version.h (revision 64893) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.2" -#define RUBY_RELEASE_DATE "2018-09-03" -#define RUBY_PATCHLEVEL 90 +#define RUBY_RELEASE_DATE "2018-10-01" +#define RUBY_PATCHLEVEL 91 #define RUBY_RELEASE_YEAR 2018 -#define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 3 +#define RUBY_RELEASE_MONTH 10 +#define RUBY_RELEASE_DAY 1 #include "ruby/version.h" Index: ruby_2_5/bootstraptest/test_flow.rb =================================================================== --- ruby_2_5/bootstraptest/test_flow.rb (revision 64892) +++ ruby_2_5/bootstraptest/test_flow.rb (revision 64893) @@ -589,3 +589,13 @@ assert_equal "foo", %q{ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/bootstraptest/test_flow.rb#L589 end Bug6460.new.m1 }, '[ruby-dev:46372]' + +assert_equal "foo", %q{ + obj = "foo" + if obj || any1 + any2 = any2 + else + raise obj.inspect + end + obj +}, '[ruby-core:87830]' Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 64892) +++ ruby_2_5 (revision 64893) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r63868,63870 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/