Skip to content

Commit

Permalink
JIT: eliminate check for undefined constant if there is a persistent …
Browse files Browse the repository at this point in the history
…constant
  • Loading branch information
dstogov committed Sep 7, 2021
1 parent d4ed6b6 commit 1bb6cf5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
19 changes: 19 additions & 0 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,25 @@ static bool zend_jit_may_avoid_refcounting(const zend_op *opline)
return 0;
}

static bool zend_jit_is_persistent_constant(zval *key, uint32_t flags)
{
zval *zv;
zend_constant *c = NULL;

/* null/true/false are resolved during compilation, so don't check for them here. */
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
if (zv) {
c = (zend_constant*)Z_PTR_P(zv);
} else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
key++;
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
if (zv) {
c = (zend_constant*)Z_PTR_P(zv);
}
}
return c && (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
}

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)
{
zend_property_info *info = NULL;
Expand Down
10 changes: 6 additions & 4 deletions ext/opcache/jit/zend_jit_arm64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -13892,10 +13892,12 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, FCARG1x, opline->extended_value, TMP1
| // if (c != NULL)
| cbz REG0, >9
| // if (!IS_SPECIAL_CACHE_VAL(c))
|| ZEND_ASSERT(CACHE_SPECIAL == 1);
| TST_64_WITH_ONE REG0
| bne >9
if (!zend_jit_is_persistent_constant(zv, opline->op1.num)) {
| // if (!IS_SPECIAL_CACHE_VAL(c))
|| ZEND_ASSERT(CACHE_SPECIAL == 1);
| TST_64_WITH_ONE REG0
| bne >9
}
|8:

if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) {
Expand Down
8 changes: 5 additions & 3 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -14740,9 +14740,11 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
| // if (c != NULL)
| test r0, r0
| jz >9
| // if (!IS_SPECIAL_CACHE_VAL(c))
| test r0, CACHE_SPECIAL
| jnz >9
if (!zend_jit_is_persistent_constant(zv, opline->op1.num)) {
| // if (!IS_SPECIAL_CACHE_VAL(c))
| test r0, CACHE_SPECIAL
| jnz >9
}
|8:

if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) {
Expand Down

0 comments on commit 1bb6cf5

Please sign in to comment.