Skip to content

Commit c6e895a

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Disable type narrowing optimization when we contruct SSA for JIT
2 parents a529d0d + 297117b commit c6e895a

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
@@ -3968,7 +3968,7 @@ static bool can_convert_to_double(
39683968
for (phi = var->phi_use_chain; phi; phi = zend_ssa_next_use_phi(ssa, var_num, phi)) {
39693969
/* Check that narrowing can actually be useful */
39703970
type = ssa->var_info[phi->ssa_var].type;
3971-
if (type & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) {
3971+
if ((type & MAY_BE_ANY) & ~(MAY_BE_LONG|MAY_BE_DOUBLE)) {
39723972
return 0;
39733973
}
39743974

@@ -4315,8 +4315,10 @@ static int zend_infer_types(const zend_op_array *op_array, const zend_script *sc
43154315
return FAILURE;
43164316
}
43174317

4318-
/* Narrowing integer initialization to doubles */
4319-
zend_type_narrowing(op_array, script, ssa, optimization_level);
4318+
if (optimization_level & ZEND_OPTIMIZER_NARROW_TO_DOUBLE) {
4319+
/* Narrowing integer initialization to doubles */
4320+
zend_type_narrowing(op_array, script, ssa, optimization_level);
4321+
}
43204322

43214323
if (ZEND_FUNC_INFO(op_array)) {
43224324
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
@@ -1346,7 +1346,8 @@ static int zend_jit_op_array_analyze2(const zend_op_array *op_array, zend_script
13461346
&& op_array->last_try_catch == 0
13471347
&& !(op_array->fn_flags & ZEND_ACC_GENERATOR)
13481348
&& !(ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS)) {
1349-
if (zend_ssa_inference(&CG(arena), op_array, script, ssa, optimization_level) != SUCCESS) {
1349+
if (zend_ssa_inference(&CG(arena), op_array, script, ssa,
1350+
optimization_level & ~ZEND_OPTIMIZER_NARROW_TO_DOUBLE) != SUCCESS) {
13501351
return FAILURE;
13511352
}
13521353
}

0 commit comments

Comments
 (0)