ruby-changes:51656
From: mame <ko1@a...>
Date: Fri, 6 Jul 2018 13:52:39 +0900 (JST)
Subject: [ruby-changes:51656] mame:r63868 (trunk): Fix a bug of peephole optimization
mame 2018-07-06 13:52:33 +0900 (Fri, 06 Jul 2018) New Revision: 63868 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63868 Log: 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]. Modified files: trunk/bootstraptest/test_flow.rb trunk/compile.c Index: bootstraptest/test_flow.rb =================================================================== --- bootstraptest/test_flow.rb (revision 63867) +++ bootstraptest/test_flow.rb (revision 63868) @@ -589,3 +589,13 @@ assert_equal "foo", %q{ https://github.com/ruby/ruby/blob/trunk/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: compile.c =================================================================== --- compile.c (revision 63867) +++ compile.c (revision 63868) @@ -2730,7 +2730,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2730 ELEM_INSERT_NEXT(&dniobj->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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/