Skip to content

Commit 1bb6cf5

Browse files
committed
JIT: eliminate check for undefined constant if there is a persistent constant
1 parent d4ed6b6 commit 1bb6cf5

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,25 @@ static bool zend_jit_may_avoid_refcounting(const zend_op *opline)
576576
return 0;
577577
}
578578

579+
static bool zend_jit_is_persistent_constant(zval *key, uint32_t flags)
580+
{
581+
zval *zv;
582+
zend_constant *c = NULL;
583+
584+
/* null/true/false are resolved during compilation, so don't check for them here. */
585+
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
586+
if (zv) {
587+
c = (zend_constant*)Z_PTR_P(zv);
588+
} else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
589+
key++;
590+
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
591+
if (zv) {
592+
c = (zend_constant*)Z_PTR_P(zv);
593+
}
594+
}
595+
return c && (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
596+
}
597+
579598
static zend_property_info* zend_get_known_property_info(const zend_op_array *op_array, zend_class_entry *ce, zend_string *member, bool on_this, zend_string *filename)
580599
{
581600
zend_property_info *info = NULL;

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13892,10 +13892,12 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1389213892
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, FCARG1x, opline->extended_value, TMP1
1389313893
| // if (c != NULL)
1389413894
| cbz REG0, >9
13895-
| // if (!IS_SPECIAL_CACHE_VAL(c))
13896-
|| ZEND_ASSERT(CACHE_SPECIAL == 1);
13897-
| TST_64_WITH_ONE REG0
13898-
| bne >9
13895+
if (!zend_jit_is_persistent_constant(zv, opline->op1.num)) {
13896+
| // if (!IS_SPECIAL_CACHE_VAL(c))
13897+
|| ZEND_ASSERT(CACHE_SPECIAL == 1);
13898+
| TST_64_WITH_ONE REG0
13899+
| bne >9
13900+
}
1389913901
|8:
1390013902

1390113903
if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14740,9 +14740,11 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1474014740
| // if (c != NULL)
1474114741
| test r0, r0
1474214742
| jz >9
14743-
| // if (!IS_SPECIAL_CACHE_VAL(c))
14744-
| test r0, CACHE_SPECIAL
14745-
| jnz >9
14743+
if (!zend_jit_is_persistent_constant(zv, opline->op1.num)) {
14744+
| // if (!IS_SPECIAL_CACHE_VAL(c))
14745+
| test r0, CACHE_SPECIAL
14746+
| jnz >9
14747+
}
1474614748
|8:
1474714749

1474814750
if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) {

0 commit comments

Comments
 (0)