summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--compile.c12
2 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 3128441fcf..7921ccbf62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Nov 22 16:37:10 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * compile.c (iseq_peephole_optimize): eliminate always/never
+ branches after a literal object and when the value is used after
+ the branch.
+
Sun Nov 22 01:23:43 2015 Naohisa Goto <ngotogenome@gmail.com>
* configure.in: Add -D_XOPEN_SOURCE=500 (or 600 or 700) on Solaris
diff --git a/compile.c b/compile.c
index c199424ca1..54cf643f48 100644
--- a/compile.c
+++ b/compile.c
@@ -2053,8 +2053,18 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
* =>
* jump L1
*
+ * putstring ".."
+ * dup
+ * if L1
+ * =>
+ * putstring ".."
+ * jump L1
+ *
*/
int cond;
+ if (prev_dup && pobj->link.prev->type == ISEQ_ELEMENT_INSN) {
+ pobj = (INSN *)pobj->link.prev;
+ }
if (pobj->insn_id == BIN(putobject)) {
cond = (iobj->insn_id == BIN(branchif) ?
OPERAND_AT(pobj, 0) != Qfalse :
@@ -2069,7 +2079,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
cond = iobj->insn_id != BIN(branchif);
}
else break;
- REMOVE_ELEM(&pobj->link);
+ REMOVE_ELEM(iobj->link.prev);
if (cond) {
iobj->insn_id = BIN(jump);
goto again;