Skip to content

Commit 90f822d

Browse files
committed
Support for few more opcodes
1 parent cffee2f commit 90f822d

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ static zend_bool try_replace_op1(
239239
if (zend_optimizer_update_op1_const(ctx->op_array, opline, &zv)) {
240240
return 1;
241241
} else {
242+
// TODO: check the following special cases ???
243+
switch (opline->opcode) {
244+
case ZEND_FETCH_LIST:
245+
case ZEND_CASE:
246+
case ZEND_SWITCH_STRING:
247+
case ZEND_SWITCH_LONG:
248+
if (Z_TYPE(zv) == IS_STRING) {
249+
zend_string_hash_val(Z_STR(zv));
250+
}
251+
opline->op1.constant = zend_optimizer_add_literal(ctx->op_array, &zv);
252+
opline->op1_type = IS_CONST;
253+
return 1;
254+
}
242255
zval_ptr_dtor_nogc(&zv);
243256
}
244257
}
@@ -300,14 +313,14 @@ static inline int fetch_array_elem(zval **result, zval *op1, zval *op2) {
300313
}
301314
}
302315

303-
static inline int ct_eval_fetch_dim(zval *result, zval *op1, zval *op2) {
316+
static inline int ct_eval_fetch_dim(zval *result, zval *op1, zval *op2, int support_strings) {
304317
if (Z_TYPE_P(op1) == IS_ARRAY) {
305318
zval *value;
306319
if (fetch_array_elem(&value, op1, op2) == SUCCESS && value) {
307320
ZVAL_COPY(result, value);
308321
return SUCCESS;
309322
}
310-
} else if (Z_TYPE_P(op1) == IS_STRING) {
323+
} else if (support_strings && Z_TYPE_P(op1) == IS_STRING) {
311324
zend_long index;
312325
if (zval_to_string_offset(&index, op2) == FAILURE) {
313326
return FAILURE;
@@ -697,6 +710,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
697710
case ZEND_BW_AND:
698711
case ZEND_BW_XOR:
699712
case ZEND_BOOL_XOR:
713+
case ZEND_CASE:
700714
SKIP_IF_TOP(op1);
701715
SKIP_IF_TOP(op2);
702716

@@ -796,11 +810,23 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
796810
}
797811
SET_RESULT_BOT(result);
798812
break;
813+
case ZEND_COUNT:
814+
SKIP_IF_TOP(op1);
815+
if (Z_TYPE_P(op1) == IS_ARRAY) {
816+
ZVAL_LONG(&zv, zend_hash_num_elements(Z_ARRVAL_P(op1)));
817+
SET_RESULT(result, &zv);
818+
zval_ptr_dtor_nogc(&zv);
819+
break;
820+
}
821+
SET_RESULT_BOT(result);
822+
break;
799823
case ZEND_FETCH_DIM_R:
824+
case ZEND_FETCH_DIM_IS:
825+
case ZEND_FETCH_LIST:
800826
SKIP_IF_TOP(op1);
801827
SKIP_IF_TOP(op2);
802828

803-
if (ct_eval_fetch_dim(&zv, op1, op2) == SUCCESS) {
829+
if (ct_eval_fetch_dim(&zv, op1, op2, (opline->opcode != ZEND_FETCH_LIST)) == SUCCESS) {
804830
SET_RESULT(result, &zv);
805831
zval_ptr_dtor_nogc(&zv);
806832
break;

0 commit comments

Comments
 (0)