Skip to content

Commit 2ae1e7a

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fix register allocator
2 parents 27d2fdd + ac8a53c commit 2ae1e7a

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,6 +3560,14 @@ static int zend_jit_store_var(dasm_State **Dst, uint32_t info, int var, zend_reg
35603560
return zend_jit_spill_store(Dst, src, dst, info, set_type);
35613561
}
35623562

3563+
static int zend_jit_store_var_type(dasm_State **Dst, int var, uint8_t type)
3564+
{
3565+
zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var));
3566+
3567+
| SET_ZVAL_TYPE_INFO dst, type, TMP1w, TMP2
3568+
return 1;
3569+
}
3570+
35633571
static int zend_jit_store_var_if_necessary(dasm_State **Dst, int var, zend_jit_addr src, uint32_t info)
35643572
{
35653573
if (Z_MODE(src) == IS_REG && Z_STORE(src)) {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6704,6 +6704,22 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
67046704
if (p->stop == ZEND_JIT_TRACE_STOP_LOOP
67056705
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_CALL
67066706
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
6707+
if (ra) {
6708+
zend_ssa_phi *phi = ssa->blocks[1].phis;
6709+
6710+
while (phi) {
6711+
if (ra[phi->ssa_var]
6712+
&& ra[phi->sources[1]]
6713+
&& STACK_MEM_TYPE(stack, phi->var) != STACK_TYPE(stack, phi->var)
6714+
&& (ra[phi->ssa_var]->flags & (ZREG_LOAD|ZREG_STORE)) == 0
6715+
&& (ra[phi->sources[1]]->flags & (ZREG_LOAD|ZREG_STORE)) == 0) {
6716+
/* Store actual type to memory to avoid deoptimization mistakes */
6717+
/* TODO: Alternatively, we may try to update alredy generated deoptimization info */
6718+
zend_jit_store_var_type(&dasm_state, phi->var, STACK_TYPE(stack, phi->var));
6719+
}
6720+
phi = phi->next;
6721+
}
6722+
}
67076723
if (p->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
67086724
if ((t->flags & ZEND_JIT_TRACE_USES_INITIAL_IP)
67096725
&& !zend_jit_set_ip(&dasm_state, p->opline)) {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,14 @@ static int zend_jit_store_var(dasm_State **Dst, uint32_t info, int var, zend_reg
39003900
return zend_jit_spill_store(Dst, src, dst, info, set_type);
39013901
}
39023902

3903+
static int zend_jit_store_var_type(dasm_State **Dst, int var, uint8_t type)
3904+
{
3905+
zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var));
3906+
3907+
| SET_ZVAL_TYPE_INFO dst, type
3908+
return 1;
3909+
}
3910+
39033911
static int zend_jit_store_var_if_necessary(dasm_State **Dst, int var, zend_jit_addr src, uint32_t info)
39043912
{
39053913
if (Z_MODE(src) == IS_REG && Z_STORE(src)) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Register Alloction 011: Missed type store
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function foo($y) {
11+
for ($cnt=0;$cnt<6;$cnt++) {
12+
$i = $y;
13+
for ($i=0;$i<1;)
14+
for(;$i<1;)
15+
for(;$i<1;$i++)
16+
for(;$y;);
17+
for($i=0;$i< 1;$i++)
18+
for(;$y;);
19+
}
20+
}
21+
foo(null);
22+
?>
23+
DONE
24+
--EXPECTF--
25+
DONE

0 commit comments

Comments
 (0)