mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
avoid extra dup and pop in compile_op_asgn2
Co-authored-by: John Hawthorn <jhawthorn@github.com>
This commit is contained in:
parent
aafbc9068f
commit
fbaac837cf
Notes:
git
2022-09-23 01:47:36 +09:00
2 changed files with 32 additions and 11 deletions
8
benchmark/vm_lvar_cond_set.yml
Normal file
8
benchmark/vm_lvar_cond_set.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
benchmark:
|
||||||
|
vm_lvar_cond_set: |
|
||||||
|
a ||= 1
|
||||||
|
b ||= 1
|
||||||
|
c ||= 1
|
||||||
|
d ||= 1
|
||||||
|
nil
|
||||||
|
loop_count: 30000000
|
25
compile.c
25
compile.c
|
@ -8663,6 +8663,17 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
|
||||||
lfin: # o ?
|
lfin: # o ?
|
||||||
pop # o
|
pop # o
|
||||||
|
|
||||||
|
# or (popped)
|
||||||
|
if lcfin # r
|
||||||
|
eval v # r v
|
||||||
|
send a= # ?
|
||||||
|
jump lfin # ?
|
||||||
|
|
||||||
|
lcfin: # r
|
||||||
|
|
||||||
|
lfin: # ?
|
||||||
|
pop #
|
||||||
|
|
||||||
# and
|
# and
|
||||||
dup # r o o
|
dup # r o o
|
||||||
unless lcfin
|
unless lcfin
|
||||||
|
@ -8691,32 +8702,36 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
|
||||||
ADD_SEND_WITH_FLAG(ret, node, vid, INT2FIX(0), INT2FIX(asgnflag));
|
ADD_SEND_WITH_FLAG(ret, node, vid, INT2FIX(0), INT2FIX(asgnflag));
|
||||||
|
|
||||||
if (atype == idOROP || atype == idANDOP) {
|
if (atype == idOROP || atype == idANDOP) {
|
||||||
|
if (!popped) {
|
||||||
ADD_INSN(ret, node, dup);
|
ADD_INSN(ret, node, dup);
|
||||||
|
}
|
||||||
if (atype == idOROP) {
|
if (atype == idOROP) {
|
||||||
ADD_INSNL(ret, node, branchif, lcfin);
|
ADD_INSNL(ret, node, branchif, lcfin);
|
||||||
}
|
}
|
||||||
else { /* idANDOP */
|
else { /* idANDOP */
|
||||||
ADD_INSNL(ret, node, branchunless, lcfin);
|
ADD_INSNL(ret, node, branchunless, lcfin);
|
||||||
}
|
}
|
||||||
|
if (!popped) {
|
||||||
ADD_INSN(ret, node, pop);
|
ADD_INSN(ret, node, pop);
|
||||||
|
}
|
||||||
CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value));
|
CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value));
|
||||||
|
if (!popped) {
|
||||||
ADD_INSN(ret, node, swap);
|
ADD_INSN(ret, node, swap);
|
||||||
ADD_INSN1(ret, node, topn, INT2FIX(1));
|
ADD_INSN1(ret, node, topn, INT2FIX(1));
|
||||||
|
}
|
||||||
ADD_SEND_WITH_FLAG(ret, node, aid, INT2FIX(1), INT2FIX(asgnflag));
|
ADD_SEND_WITH_FLAG(ret, node, aid, INT2FIX(1), INT2FIX(asgnflag));
|
||||||
ADD_INSNL(ret, node, jump, lfin);
|
ADD_INSNL(ret, node, jump, lfin);
|
||||||
|
|
||||||
ADD_LABEL(ret, lcfin);
|
ADD_LABEL(ret, lcfin);
|
||||||
|
if (!popped) {
|
||||||
ADD_INSN(ret, node, swap);
|
ADD_INSN(ret, node, swap);
|
||||||
|
}
|
||||||
|
|
||||||
ADD_LABEL(ret, lfin);
|
ADD_LABEL(ret, lfin);
|
||||||
ADD_INSN(ret, node, pop);
|
ADD_INSN(ret, node, pop);
|
||||||
if (lskip) {
|
if (lskip) {
|
||||||
ADD_LABEL(ret, lskip);
|
ADD_LABEL(ret, lskip);
|
||||||
}
|
}
|
||||||
if (popped) {
|
|
||||||
/* we can apply more optimize */
|
|
||||||
ADD_INSN(ret, node, pop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value));
|
CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value));
|
||||||
|
@ -8848,9 +8863,7 @@ compile_op_log(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node,
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_LABEL(ret, lassign);
|
ADD_LABEL(ret, lassign);
|
||||||
|
|
||||||
CHECK(COMPILE_(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value, popped));
|
CHECK(COMPILE_(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value, popped));
|
||||||
|
|
||||||
ADD_LABEL(ret, lfin);
|
ADD_LABEL(ret, lfin);
|
||||||
return COMPILE_OK;
|
return COMPILE_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue