Skip to content

Commit 74f7f2c

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: Fix incorrect type store elimination Fix incorrect register allocation
2 parents f1ae135 + a23f3dd commit 74f7f2c

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,13 +1952,17 @@ static int zend_jit_compute_liveness(const zend_op_array *op_array, zend_ssa *ss
19521952
if (ssa->ops[line].op1_use >= 0 &&
19531953
intervals[ssa->ops[line].op1_use] &&
19541954
ssa->ops[line].op1_use_chain < 0 &&
1955-
!ssa->vars[ssa->ops[line].op1_use].phi_use_chain) {
1955+
!ssa->vars[ssa->ops[line].op1_use].phi_use_chain &&
1956+
(ssa->var_info[i].type & MAY_BE_ANY) ==
1957+
(ssa->var_info[ssa->ops[line].op1_use].type & MAY_BE_ANY)) {
19561958
zend_jit_add_hint(intervals, i, ssa->ops[line].op1_use);
19571959
} else if (opline->opcode != ZEND_SUB &&
19581960
ssa->ops[line].op2_use >= 0 &&
19591961
intervals[ssa->ops[line].op2_use] &&
19601962
ssa->ops[line].op2_use_chain < 0 &&
1961-
!ssa->vars[ssa->ops[line].op2_use].phi_use_chain) {
1963+
!ssa->vars[ssa->ops[line].op2_use].phi_use_chain &&
1964+
(ssa->var_info[i].type & MAY_BE_ANY) ==
1965+
(ssa->var_info[ssa->ops[line].op2_use].type & MAY_BE_ANY)) {
19621966
zend_jit_add_hint(intervals, i, ssa->ops[line].op2_use);
19631967
}
19641968
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,9 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
32133213
if (ssa->ops[line].op1_use >= 0 &&
32143214
intervals[ssa->ops[line].op1_use] &&
32153215
ssa->ops[line].op1_use_chain < 0 &&
3216-
!ssa->vars[ssa->ops[line].op1_use].phi_use_chain) {
3216+
!ssa->vars[ssa->ops[line].op1_use].phi_use_chain &&
3217+
(ssa->var_info[i].type & MAY_BE_ANY) ==
3218+
(ssa->var_info[ssa->ops[line].op1_use].type & MAY_BE_ANY)) {
32173219

32183220
zend_ssa_phi *phi = ssa->vars[ssa->ops[line].op1_use].definition_phi;
32193221
if (phi &&
@@ -3226,7 +3228,9 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
32263228
ssa->ops[line].op2_use >= 0 &&
32273229
intervals[ssa->ops[line].op2_use] &&
32283230
ssa->ops[line].op2_use_chain < 0 &&
3229-
!ssa->vars[ssa->ops[line].op2_use].phi_use_chain) {
3231+
!ssa->vars[ssa->ops[line].op2_use].phi_use_chain &&
3232+
(ssa->var_info[i].type & MAY_BE_ANY) ==
3233+
(ssa->var_info[ssa->ops[line].op2_use].type & MAY_BE_ANY)) {
32303234

32313235
zend_ssa_phi *phi = ssa->vars[ssa->ops[line].op2_use].definition_phi;
32323236
if (phi &&
@@ -4874,14 +4878,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
48744878
break;
48754879
}
48764880
op2_addr = OP2_REG_ADDR();
4881+
op2_info = OP2_INFO();
48774882
if (ra
48784883
&& ssa_op->op2_def >= 0
4879-
&& !ssa->vars[ssa_op->op2_def].no_val) {
4884+
&& (!ssa->vars[ssa_op->op2_def].no_val
4885+
|| (zend_jit_trace_type_to_info(STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var))) & MAY_BE_ANY) !=
4886+
(op2_info & MAY_BE_ANY))) {
48804887
op2_def_addr = OP2_DEF_REG_ADDR();
48814888
} else {
48824889
op2_def_addr = op2_addr;
48834890
}
4884-
op2_info = OP2_INFO();
48854891
CHECK_OP2_TRACE_TYPE();
48864892
op1_info = OP1_INFO();
48874893
if ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_LONG

ext/opcache/tests/jit/add_013.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
JIT ADD: 013 register allocation (incorrect hinting)
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 y(){
11+
$j = 2;
12+
for (; $a = $j - 7 + $y = $a - 7; $a = $a + 1 / 3) {
13+
$j++;
14+
if ($j > 4) break;
15+
}
16+
}
17+
?>
18+
DONE
19+
--EXPECT--
20+
DONE

ext/opcache/tests/jit/assign_050.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
JIT ASSIGN: incorrect type store elimination
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
function foo($a) {
12+
$b = $a;
13+
$b =! $a = $a + $b & $b & $b = $b = $a = $a + $b & $a += $a;
14+
$b = $b = $a = $a + $b & $b & $b = $a = $a + $b = $b = $a = $a + $b = $a += $a;
15+
}
16+
17+
for ($i = 0; $i < 3; $i++) {
18+
@foo(39087589046889428661);
19+
}
20+
?>
21+
DONE
22+
--EXPECT--
23+
DONE

0 commit comments

Comments
 (0)