aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-11-06 12:39:57 -0800
committerJeremy Evans <code@jeremyevans.net>2023-12-07 11:27:55 -0800
commit95615872e32156d9add8fd3afd136dd73fd6aa1a (patch)
treef0f53fc438333d98ba6381cbef89f6ec393e22f9 /compile.c
parent1731dd05a7f9fcdef1ea1c25f7a3e072679c3d3a (diff)
downloadruby-95615872e32156d9add8fd3afd136dd73fd6aa1a.tar.gz
Eliminate array allocation for f(*a, **lvar, &lvar) and f(*a, **@iv, &@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.
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 4ba332ff1f..2a56579b98 100644
--- a/compile.c
+++ b/compile.c
@@ -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;
+ }
+ }
}
}
}