Skip to content

Commit ee38e3a

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Disable type narrowing optimization when we contruct SSA for JIT
2 parents fbdded1 + c6e895a commit ee38e3a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,7 @@ static bool can_convert_to_double(
40104010
for (phi = var->phi_use_chain; phi; phi = zend_ssa_next_use_phi(ssa, var_num, phi)) {
40114011
/* Check that narrowing can actually be useful */
40124012
type = ssa->var_info[phi->ssa_var].type;
4013-
if (type & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) {
4013+
if ((type & MAY_BE_ANY) & ~(MAY_BE_LONG|MAY_BE_DOUBLE)) {
40144014
return 0;
40154015
}
40164016

@@ -4357,8 +4357,10 @@ static zend_result zend_infer_types(const zend_op_array *op_array, const zend_sc
43574357
return FAILURE;
43584358
}
43594359

4360-
/* Narrowing integer initialization to doubles */
4361-
zend_type_narrowing(op_array, script, ssa, optimization_level);
4360+
if (optimization_level & ZEND_OPTIMIZER_NARROW_TO_DOUBLE) {
4361+
/* Narrowing integer initialization to doubles */
4362+
zend_type_narrowing(op_array, script, ssa, optimization_level);
4363+
}
43624364

43634365
if (ZEND_FUNC_INFO(op_array)) {
43644366
zend_func_return_info(op_array, script, 1, 0, &ZEND_FUNC_INFO(op_array)->return_info);

Zend/Optimizer/zend_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#define ZEND_OPTIMIZER_IGNORE_OVERLOADING (1<<16) /* (unsafe) Ignore possibility of operator overloading */
4646

47+
#define ZEND_OPTIMIZER_NARROW_TO_DOUBLE (1<<17) /* try to narrow long constant assignments to double */
48+
4749
#define ZEND_OPTIMIZER_ALL_PASSES 0x7FFFFFFF
4850

4951
#define DEFAULT_OPTIMIZATION_LEVEL "0x7FFEBFFF"

ext/opcache/jit/zend_jit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,8 @@ static int zend_jit_op_array_analyze2(const zend_op_array *op_array, zend_script
13321332
&& op_array->last_try_catch == 0
13331333
&& !(op_array->fn_flags & ZEND_ACC_GENERATOR)
13341334
&& !(ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS)) {
1335-
if (zend_ssa_inference(&CG(arena), op_array, script, ssa, optimization_level) != SUCCESS) {
1335+
if (zend_ssa_inference(&CG(arena), op_array, script, ssa,
1336+
optimization_level & ~ZEND_OPTIMIZER_NARROW_TO_DOUBLE) != SUCCESS) {
13361337
return FAILURE;
13371338
}
13381339
}

0 commit comments

Comments
 (0)