Skip to content

Commit c5d93ae

Browse files
shqkingdstogov
authored andcommitted
Fixed incorrec immediate encoding when using LEA optimization
1 parent c0e4932 commit c5d93ae

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,7 @@ static int zend_jit_math_long_long(dasm_State **Dst,
42874287
!may_overflow &&
42884288
Z_MODE(op1_addr) == IS_REG &&
42894289
Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4290-
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op2_addr)))) {
4290+
IS_SIGNED_32BIT(-Z_LVAL_P(Z_ZV(op2_addr)))) {
42914291
| lea Ra(result_reg), [Ra(Z_REG(op1_addr))-Z_LVAL_P(Z_ZV(op2_addr))]
42924292
} else {
42934293
| GET_ZVAL_LVAL result_reg, op1_addr

ext/opcache/tests/jit/bug81225_2.phpt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--TEST--
2+
Bug #81225: Wrong result with pow operator with JIT enabled
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
opcache.jit=function
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
11+
--FILE--
12+
<?php
13+
function add_with_positive(int $a) {
14+
$a = $a % 10;
15+
$b = $a + 1;
16+
$c = $a + 100;
17+
$d = $a + 2147483647; // 0x7fff,ffff
18+
$e = $a + 2147483648; // 0x8000,0000 cannot encoded as imm field of lea r1, [r2 + imm]
19+
$f = $a + 78187493394; // 0x12,1234,5678 cannot encoded as imm field of lea r1, [r2 + imm]
20+
var_dump($b, $c, $d, $e, $f);
21+
}
22+
23+
function add_with_negative(int $a) {
24+
$a = $a % 10;
25+
$b = $a + (-1);
26+
$c = $a + (-100);
27+
$d = $a + (-2147483648); // 0xFFFF,FFFF,8000,0000
28+
$e = $a + (-2147483649); // 0xFFFF,FFFF,7FFF,FFFF cannot encoded as imm field of lea r1, [r2 + imm]
29+
$f = $a + (-261458978401740); // 0xFFFF,1234,5678,1234 cannot encoded as imm field of lea r1, [r2 + imm]
30+
var_dump($b, $c, $d, $e, $f);
31+
}
32+
33+
function sub_with_positive(int $a) {
34+
$a = $a % 10;
35+
$b = $a - 1;
36+
$c = $a - 100;
37+
$d = $a - 2147483647; // 0x7fff,ffff
38+
$e = $a - 2147483648; // 0x8000,0000
39+
$f = $a - 2147483649; // 0x8000,0001 cannot encoded as imm field of lea r1, [r2 + imm]
40+
$g = $a - 78187493394; // 0x12,1234,5678 cannot encoded as imm field of lea r1, [r2 + imm]
41+
var_dump($b, $c, $d, $e, $f, $g);
42+
}
43+
44+
function sub_with_negative(int $a) {
45+
$a = $a % 10;
46+
$b = $a - (-1);
47+
$c = $a - (-100);
48+
$d = $a - (-2147483647); // 0xFFFF,FFFF,8000,0001
49+
$e = $a - (-2147483648); // 0xFFFF,FFFF,8000,0000 cannot encoded as imm field of lea r1, [r2 + imm]
50+
$f = $a - (-2147483649); // 0xFFFF,FFFF,7FFF,FFFF cannot encoded as imm field of lea r1, [r2 + imm]
51+
$g = $a - (-261458978401740); // 0xFFFF,1234,5678,1234 cannot encoded as imm field of lea r1, [r2 + imm]
52+
var_dump($b, $c, $d, $e, $f, $g);
53+
}
54+
55+
add_with_positive(2);
56+
add_with_negative(2);
57+
sub_with_positive(2);
58+
sub_with_negative(2);
59+
?>
60+
--EXPECT--
61+
int(3)
62+
int(102)
63+
int(2147483649)
64+
int(2147483650)
65+
int(78187493396)
66+
int(1)
67+
int(-98)
68+
int(-2147483646)
69+
int(-2147483647)
70+
int(-261458978401738)
71+
int(1)
72+
int(-98)
73+
int(-2147483645)
74+
int(-2147483646)
75+
int(-2147483647)
76+
int(-78187493392)
77+
int(3)
78+
int(102)
79+
int(2147483649)
80+
int(2147483650)
81+
int(2147483651)
82+
int(261458978401742)

0 commit comments

Comments
 (0)