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
|
35
compile.c
35
compile.c
|
@ -8663,6 +8663,17 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node
|
|||
lfin: # o ?
|
||||
pop # o
|
||||
|
||||
# or (popped)
|
||||
if lcfin # r
|
||||
eval v # r v
|
||||
send a= # ?
|
||||
jump lfin # ?
|
||||
|
||||
lcfin: # r
|
||||
|
||||
lfin: # ?
|
||||
pop #
|
||||
|
||||
# and
|
||||
dup # r o o
|
||||
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));
|
||||
|
||||
if (atype == idOROP || atype == idANDOP) {
|
||||
ADD_INSN(ret, node, dup);
|
||||
if (!popped) {
|
||||
ADD_INSN(ret, node, dup);
|
||||
}
|
||||
if (atype == idOROP) {
|
||||
ADD_INSNL(ret, node, branchif, lcfin);
|
||||
}
|
||||
else { /* idANDOP */
|
||||
ADD_INSNL(ret, node, branchunless, lcfin);
|
||||
}
|
||||
ADD_INSN(ret, node, pop);
|
||||
if (!popped) {
|
||||
ADD_INSN(ret, node, pop);
|
||||
}
|
||||
CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value));
|
||||
ADD_INSN(ret, node, swap);
|
||||
ADD_INSN1(ret, node, topn, INT2FIX(1));
|
||||
if (!popped) {
|
||||
ADD_INSN(ret, node, swap);
|
||||
ADD_INSN1(ret, node, topn, INT2FIX(1));
|
||||
}
|
||||
ADD_SEND_WITH_FLAG(ret, node, aid, INT2FIX(1), INT2FIX(asgnflag));
|
||||
ADD_INSNL(ret, node, jump, lfin);
|
||||
|
||||
ADD_LABEL(ret, lcfin);
|
||||
ADD_INSN(ret, node, swap);
|
||||
if (!popped) {
|
||||
ADD_INSN(ret, node, swap);
|
||||
}
|
||||
|
||||
ADD_LABEL(ret, lfin);
|
||||
ADD_INSN(ret, node, pop);
|
||||
if (lskip) {
|
||||
ADD_LABEL(ret, lskip);
|
||||
}
|
||||
if (popped) {
|
||||
/* we can apply more optimize */
|
||||
ADD_INSN(ret, node, pop);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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);
|
||||
|
||||
CHECK(COMPILE_(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value, popped));
|
||||
|
||||
ADD_LABEL(ret, lfin);
|
||||
return COMPILE_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue