Skip to content

Commit 2b3620d

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: Fix register allocator
2 parents c872056 + 2ae1e7a commit 2b3620d

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
@@ -3555,6 +3555,14 @@ static int zend_jit_store_var(dasm_State **Dst, uint32_t info, int var, zend_reg
35553555
return zend_jit_spill_store(Dst, src, dst, info, set_type);
35563556
}
35573557

3558+
static int zend_jit_store_var_type(dasm_State **Dst, int var, uint8_t type)
3559+
{
3560+
zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var));
3561+
3562+
| SET_ZVAL_TYPE_INFO dst, type, TMP1w, TMP2
3563+
return 1;
3564+
}
3565+
35583566
static int zend_jit_store_var_if_necessary(dasm_State **Dst, int var, zend_jit_addr src, uint32_t info)
35593567
{
35603568
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
@@ -6721,6 +6721,22 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
67216721
if (p->stop == ZEND_JIT_TRACE_STOP_LOOP
67226722
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_CALL
67236723
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
6724+
if (ra) {
6725+
zend_ssa_phi *phi = ssa->blocks[1].phis;
6726+
6727+
while (phi) {
6728+
if (ra[phi->ssa_var]
6729+
&& ra[phi->sources[1]]
6730+
&& STACK_MEM_TYPE(stack, phi->var) != STACK_TYPE(stack, phi->var)
6731+
&& (ra[phi->ssa_var]->flags & (ZREG_LOAD|ZREG_STORE)) == 0
6732+
&& (ra[phi->sources[1]]->flags & (ZREG_LOAD|ZREG_STORE)) == 0) {
6733+
/* Store actual type to memory to avoid deoptimization mistakes */
6734+
/* TODO: Alternatively, we may try to update alredy generated deoptimization info */
6735+
zend_jit_store_var_type(&dasm_state, phi->var, STACK_TYPE(stack, phi->var));
6736+
}
6737+
phi = phi->next;
6738+
}
6739+
}
67246740
if (p->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
67256741
if ((t->flags & ZEND_JIT_TRACE_USES_INITIAL_IP)
67266742
&& !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
@@ -3895,6 +3895,14 @@ static int zend_jit_store_var(dasm_State **Dst, uint32_t info, int var, zend_reg
38953895
return zend_jit_spill_store(Dst, src, dst, info, set_type);
38963896
}
38973897

3898+
static int zend_jit_store_var_type(dasm_State **Dst, int var, uint8_t type)
3899+
{
3900+
zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var));
3901+
3902+
| SET_ZVAL_TYPE_INFO dst, type
3903+
return 1;
3904+
}
3905+
38983906
static int zend_jit_store_var_if_necessary(dasm_State **Dst, int var, zend_jit_addr src, uint32_t info)
38993907
{
39003908
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)