summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-22 07:37:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-22 07:37:13 +0000
commit792c822ec441a9a061a2c74ddd970005fab33ab6 (patch)
treef3ae9efa347087acdeb72159b61c3dba6e5b456b
parent53a619de6c1bd36b7c0ab34d273701f78b657d3a (diff)
compile.c: optimize useless branches
* compile.c (iseq_peephole_optimize): eliminate always/never branches after a literal object and when the value is used after the branch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--compile.c12
2 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 3128441..7921ccb 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 c199424..54cf643 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;