Apply optimizations for putstring to putchilledstring as well

This commit is contained in:
Nobuyoshi Nakada 2024-05-27 12:41:38 +09:00
parent 5853a38043
commit f4b475993e
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

View File

@ -3080,7 +3080,7 @@ iseq_pop_newarray(rb_iseq_t *iseq, INSN *iobj)
static int static int
is_frozen_putstring(INSN *insn, VALUE *op) is_frozen_putstring(INSN *insn, VALUE *op)
{ {
if (IS_INSN_ID(insn, putstring)) { if (IS_INSN_ID(insn, putstring) || IS_INSN_ID(insn, putchilledstring)) {
*op = OPERAND_AT(insn, 0); *op = OPERAND_AT(insn, 0);
return 1; return 1;
} }
@ -3122,6 +3122,7 @@ optimize_checktype(rb_iseq_t *iseq, INSN *iobj)
switch (INSN_OF(iobj)) { switch (INSN_OF(iobj)) {
case BIN(putstring): case BIN(putstring):
case BIN(putchilledstring):
type = INT2FIX(T_STRING); type = INT2FIX(T_STRING);
break; break;
case BIN(putnil): case BIN(putnil):
@ -3549,6 +3550,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
enum ruby_vminsn_type previ = ((INSN *)prev)->insn_id; enum ruby_vminsn_type previ = ((INSN *)prev)->insn_id;
if (previ == BIN(putobject) || previ == BIN(putnil) || if (previ == BIN(putobject) || previ == BIN(putnil) ||
previ == BIN(putself) || previ == BIN(putstring) || previ == BIN(putself) || previ == BIN(putstring) ||
previ == BIN(putchilledstring) ||
previ == BIN(dup) || previ == BIN(dup) ||
previ == BIN(getlocal) || previ == BIN(getlocal) ||
previ == BIN(getblockparam) || previ == BIN(getblockparam) ||
@ -3690,7 +3692,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
} }
} }
if (IS_INSN_ID(iobj, putstring) || if (IS_INSN_ID(iobj, putstring) || IS_INSN_ID(iobj, putchilledstring) ||
(IS_INSN_ID(iobj, putobject) && RB_TYPE_P(OPERAND_AT(iobj, 0), T_STRING))) { (IS_INSN_ID(iobj, putobject) && RB_TYPE_P(OPERAND_AT(iobj, 0), T_STRING))) {
/* /*
* putstring "" * putstring ""
@ -4080,7 +4082,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
} }
} }
} }
else if ((IS_INSN_ID(niobj, putstring) || else if ((IS_INSN_ID(niobj, putstring) || IS_INSN_ID(niobj, putchilledstring) ||
(IS_INSN_ID(niobj, putobject) && RB_TYPE_P(OPERAND_AT(niobj, 0), T_STRING))) && (IS_INSN_ID(niobj, putobject) && RB_TYPE_P(OPERAND_AT(niobj, 0), T_STRING))) &&
IS_NEXT_INSN_ID(&niobj->link, send)) { IS_NEXT_INSN_ID(&niobj->link, send)) {
const struct rb_callinfo *ci = (struct rb_callinfo *)OPERAND_AT((INSN *)niobj->link.next, 0); const struct rb_callinfo *ci = (struct rb_callinfo *)OPERAND_AT((INSN *)niobj->link.next, 0);