Skip to content

Commit 919fd56

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fixed incorrect code generation for JMPZ
2 parents 661cd1b + cd45bd0 commit 919fd56

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14765,10 +14765,20 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1476514765
op1_info = OP1_INFO();
1476614766
return (opline->op1_type & (IS_CV|IS_CONST))
1476714767
&& (op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == MAY_BE_ARRAY;
14768-
case ZEND_BOOL:
14769-
case ZEND_BOOL_NOT:
1477014768
case ZEND_JMPZ:
1477114769
case ZEND_JMPNZ:
14770+
if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) {
14771+
if (!ssa->cfg.map) {
14772+
return 0;
14773+
}
14774+
if (opline > op_array->opcodes + ssa->cfg.blocks[ssa->cfg.map[opline-op_array->opcodes]].start &&
14775+
((opline-1)->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
14776+
return 0;
14777+
}
14778+
}
14779+
ZEND_FALLTHROUGH;
14780+
case ZEND_BOOL:
14781+
case ZEND_BOOL_NOT:
1477214782
case ZEND_JMPZNZ:
1477314783
case ZEND_JMPZ_EX:
1477414784
case ZEND_JMPNZ_EX:

ext/opcache/jit/zend_jit_trace.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,13 +1771,6 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
17711771
break;
17721772
case ZEND_JMPZ:
17731773
case ZEND_JMPNZ:
1774-
if (/*opline > op_array->opcodes + ssa->cfg.blocks[b].start && ??? */
1775-
opline->op1_type == IS_TMP_VAR &&
1776-
((opline-1)->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
1777-
/* smart branch */
1778-
break;
1779-
}
1780-
ZEND_FALLTHROUGH;
17811774
case ZEND_JMPZNZ:
17821775
case ZEND_JMPZ_EX:
17831776
case ZEND_JMPNZ_EX:
@@ -5213,13 +5206,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
52135206
goto done;
52145207
case ZEND_JMPZ:
52155208
case ZEND_JMPNZ:
5216-
if (/*opline > op_array->opcodes + ssa->cfg.blocks[b].start && ??? */
5217-
opline->op1_type == IS_TMP_VAR &&
5218-
((opline-1)->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
5219-
/* smart branch */
5220-
break;
5221-
}
5222-
ZEND_FALLTHROUGH;
52235209
case ZEND_JMPZNZ:
52245210
case ZEND_JMPZ_EX:
52255211
case ZEND_JMPNZ_EX:

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15630,10 +15630,20 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1563015630
op1_info = OP1_INFO();
1563115631
return (opline->op1_type & (IS_CV|IS_CONST))
1563215632
&& (op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == MAY_BE_ARRAY;
15633-
case ZEND_BOOL:
15634-
case ZEND_BOOL_NOT:
1563515633
case ZEND_JMPZ:
1563615634
case ZEND_JMPNZ:
15635+
if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) {
15636+
if (!ssa->cfg.map) {
15637+
return 0;
15638+
}
15639+
if (opline > op_array->opcodes + ssa->cfg.blocks[ssa->cfg.map[opline-op_array->opcodes]].start &&
15640+
((opline-1)->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
15641+
return 0;
15642+
}
15643+
}
15644+
ZEND_FALLTHROUGH;
15645+
case ZEND_BOOL:
15646+
case ZEND_BOOL_NOT:
1563715647
case ZEND_JMPZNZ:
1563815648
case ZEND_JMPZ_EX:
1563915649
case ZEND_JMPNZ_EX:

ext/opcache/tests/jit/jmpz_002.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
JIT JMPZ: Separate JMPZ for "smart branch" may be only emitted by function JIT
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 test($b) {
12+
if ($b ? 0 : (X>0)){
13+
echo "Not taken\n";
14+
}
15+
}
16+
test(true);
17+
?>
18+
DONE
19+
--EXPECT--
20+
DONE

0 commit comments

Comments
 (0)