Skip to content

Commit 6e08668

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fixed NaN handling
2 parents 0b5d62e + 8a08730 commit 6e08668

File tree

2 files changed

+81
-32
lines changed

2 files changed

+81
-32
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8635,51 +8635,47 @@ static int zend_jit_bool_jmpznz(dasm_State **Dst, const zend_op *opline, uint32_
86358635
if (set_bool) {
86368636
if (exit_addr) {
86378637
if (branch_opcode == ZEND_JMPNZ || branch_opcode == ZEND_JMPNZ_EX) {
8638-
| jp >1
86398638
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
8639+
| jp &exit_addr
86408640
| jne &exit_addr
8641-
|1:
86428641
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
86438642
} else {
8644-
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
86458643
| jp >1
8644+
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
86468645
| je &exit_addr
86478646
|1:
86488647
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
86498648
}
8650-
} else if (false_label != (uint32_t)-1) { // JMPZ_EX
8649+
} else if (false_label != (uint32_t)-1) { // JMPZ_EX (p=>true, z=>false, false=>jmp)
8650+
| jp >1
86518651
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
8652-
| jp >1
8653-
| je => false_label
8654-
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
8652+
| je => false_label
86558653
|1:
8656-
} else if (true_label != (uint32_t)-1) { // JMPNZ_EX
8657-
| jp >1
86588654
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
8659-
| jne => true_label
8660-
|1:
8655+
} else if (true_label != (uint32_t)-1) { // JMPNZ_EX (p=>true, z=>false, true=>jmp)
8656+
| SET_ZVAL_TYPE_INFO res_addr, IS_TRUE
8657+
| jp => true_label
8658+
| jne => true_label
86618659
| SET_ZVAL_TYPE_INFO res_addr, IS_FALSE
8662-
} else if (set_bool_not) { // BOOL_NOT
8660+
} else if (set_bool_not) { // BOOL_NOT (p=>false, z=>true)
8661+
| mov eax, IS_FALSE
86638662
| jp >1
8663+
| jne >1
86648664
| mov eax, IS_TRUE
8665-
| je >2
86668665
|1:
8667-
| mov eax, IS_FALSE
8668-
|2:
86698666
| SET_ZVAL_TYPE_INFO res_addr, eax
8670-
} else { // BOOL
8671-
| jp >1
8667+
} else { // BOOL (p=>true, z=>false)
86728668
| mov eax, IS_TRUE
8673-
| jne >2
8674-
|1:
8669+
| jp >1
8670+
| jne >1
86758671
| mov eax, IS_FALSE
8676-
|2:
8672+
|1:
86778673
| SET_ZVAL_TYPE_INFO res_addr, eax
86788674
}
86798675
} else {
86808676
if (exit_addr) {
86818677
if (branch_opcode == ZEND_JMPNZ || branch_opcode == ZEND_JMPNZ_EX) {
8682-
| jp >1
8678+
| jp &exit_addr
86838679
| jne &exit_addr
86848680
|1:
86858681
} else {
@@ -8689,20 +8685,17 @@ static int zend_jit_bool_jmpznz(dasm_State **Dst, const zend_op *opline, uint32_
86898685
}
86908686
} else {
86918687
ZEND_ASSERT(true_label != (uint32_t)-1 || false_label != (uint32_t)-1);
8692-
if (false_label != (uint32_t)-1) {
8693-
| jp =>false_label
8694-
} else {
8695-
| jp >1
8696-
}
8697-
if (true_label != (uint32_t)-1) {
8698-
| jne =>true_label
8699-
if (false_label != (uint32_t)-1) {
8700-
| jmp =>false_label
8688+
if (false_label != (uint32_t)-1 ) {
8689+
| jp >1
8690+
| je => false_label
8691+
|1:
8692+
if (true_label != (uint32_t)-1) {
8693+
| jmp =>true_label
87018694
}
87028695
} else {
8703-
| je =>false_label
8696+
| jp => true_label
8697+
| jne => true_label
87048698
}
8705-
|1:
87068699
}
87078700
}
87088701
} else if (op1_info & (MAY_BE_ANY - (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG))) {

ext/opcache/tests/jit/nan_002.phpt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
NaN handling: 002
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(float $a) {
12+
if ($a) var_dump("1");
13+
if (!$a) var_dump("2");
14+
var_dump((bool) $a);
15+
var_dump(!$a);
16+
echo "\n";
17+
}
18+
function test1(float $a, bool $b) {
19+
var_dump($a && $b); //JMPNZ_EX
20+
}
21+
function test2(float $a, bool $b) {
22+
var_dump($a || $b); // JMPZ_EX
23+
}
24+
test(NAN);
25+
test(1.0);
26+
test(0.0);
27+
28+
test1(NAN, true);
29+
test1(1.0, true);
30+
test1(0.0, true);
31+
echo "\n";
32+
33+
test2(NAN, false);
34+
test2(1.0, false);
35+
test2(0.0, false);
36+
?>
37+
--EXPECT--
38+
string(1) "1"
39+
bool(true)
40+
bool(false)
41+
42+
string(1) "1"
43+
bool(true)
44+
bool(false)
45+
46+
string(1) "2"
47+
bool(false)
48+
bool(true)
49+
50+
bool(true)
51+
bool(true)
52+
bool(false)
53+
54+
bool(true)
55+
bool(true)
56+
bool(false)

0 commit comments

Comments
 (0)