ruby-changes:53136
From: nobu <ko1@a...>
Date: Wed, 24 Oct 2018 19:38:44 +0900 (JST)
Subject: [ruby-changes:53136] nobu:r65350 (trunk): compile.c: fix peephole optimization
nobu 2018-10-24 19:38:39 +0900 (Wed, 24 Oct 2018) New Revision: 65350 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65350 Log: compile.c: fix peephole optimization * compile.c (iseq_peephole_optimize): should `pop` before jump instruction which succeeds to `newarray` of a literal object, not after. [ruby-core:89536] [Bug #15245] Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: compile.c =================================================================== --- compile.c (revision 65349) +++ compile.c (revision 65350) @@ -2913,7 +2913,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2913 } else if (!iseq_pop_newarray(iseq, pobj)) { pobj = new_insn_core(iseq, pobj->insn_info.line_no, BIN(pop), 0, NULL); - ELEM_INSERT_NEXT(&iobj->link, &pobj->link); + ELEM_INSERT_PREV(&iobj->link, &pobj->link); } if (cond) { if (prev_dup) { Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 65349) +++ test/ruby/test_optimization.rb (revision 65350) @@ -794,4 +794,10 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L794 end assert_equal(:ok, x.bug(:ok)) end + + def test_peephole_jump_after_newarray + i = 0 + %w(1) || 2 while (i += 1) < 100 + assert_equal(100, i) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/