summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-01 12:02:17 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-01 12:02:17 +0000
commit0628973435abeccf676f3c2563579b3dbab06976 (patch)
tree77ca67418c82d0adb8a8a2212bf4c00cbd44eb65 /compile.c
parentbf0dcd5b855e7798b343bbe669f36e98afaf86e1 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 2f1e46aaa1..95ba803995 100644
--- a/compile.c
+++ b/compile.c
@@ -2469,6 +2469,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
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, LINK_ELEMENT *list, const int do_tailcal
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) {