Skip to content

Commit

Permalink
Eliminate array allocation for f(*a, **lvar, &lvar) and f(*a, **@Iv, &@…
Browse files Browse the repository at this point in the history
…Iv)

The compiler already eliminates the array allocation for
f(*a, &lvar) and f(*a, &@Iv).  If that is safe, then eliminating
it for f(*a, **lvar) and f(*a, **@Iv) as the last commit did is
as safe, and eliminating it for f(*a, **lvar, &lvar) and
f(*a, **@Iv, &@Iv) is also as safe.
  • Loading branch information
jeremyevans committed Dec 7, 2023
1 parent 1731dd0 commit 9561587
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions compile.c
Expand Up @@ -3892,6 +3892,30 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
OPERAND_AT(iobj, 0) = Qfalse;
}
}
} else if (IS_NEXT_INSN_ID(niobj, getlocal) || IS_NEXT_INSN_ID(niobj, getinstancevariable)) {
niobj = niobj->next;

/*
* Eliminate array allocation for f(*a, **lvar, &lvar) and f(*a, **@iv, &@iv)
*
* splatarray true
* getlocal / getinstancevariable
* getlocal / getinstancevariable
* send ARGS_SPLAT|KW_SPLAT|ARGS_BLOCKARG
* =>
* splatarray false
* getlocal / getinstancevariable
* getlocal / getinstancevariable
* send
*/
if (IS_NEXT_INSN_ID(niobj, send)) {
niobj = niobj->next;
unsigned int flag = vm_ci_flag((const struct rb_callinfo *)OPERAND_AT(niobj, 0));

if ((flag & VM_CALL_ARGS_SPLAT) && (flag & VM_CALL_KW_SPLAT) && (flag & VM_CALL_ARGS_BLOCKARG)) {
OPERAND_AT(iobj, 0) = Qfalse;
}
}
}
}
}
Expand Down

0 comments on commit 9561587

Please sign in to comment.