From 297117bbc58f581b4f9a36b3c5c53eac0e0883a0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 29 Nov 2021 15:51:54 +0300 Subject: [PATCH] Disable type narrowing optimization when we contruct SSA for JIT This also revets incorrect fix introduced in f9518c3850982aca41fac22b87a1e11096eb1643 --- ext/opcache/Optimizer/zend_inference.c | 8 +++++--- ext/opcache/Optimizer/zend_optimizer.h | 2 ++ ext/opcache/jit/zend_jit.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 926e3186ef8..bbecc87ca5c 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -3918,7 +3918,7 @@ static zend_bool can_convert_to_double( for (phi = var->phi_use_chain; phi; phi = zend_ssa_next_use_phi(ssa, var_num, phi)) { /* Check that narrowing can actually be useful */ type = ssa->var_info[phi->ssa_var].type; - if (type & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) { + if ((type & MAY_BE_ANY) & ~(MAY_BE_LONG|MAY_BE_DOUBLE)) { return 0; } @@ -4240,8 +4240,10 @@ static int zend_infer_types(const zend_op_array *op_array, const zend_script *sc return FAILURE; } - /* Narrowing integer initialization to doubles */ - zend_type_narrowing(op_array, script, ssa, optimization_level); + if (optimization_level & ZEND_OPTIMIZER_NARROW_TO_DOUBLE) { + /* Narrowing integer initialization to doubles */ + zend_type_narrowing(op_array, script, ssa, optimization_level); + } if (ZEND_FUNC_INFO(op_array)) { zend_func_return_info(op_array, script, 1, 0, &ZEND_FUNC_INFO(op_array)->return_info); diff --git a/ext/opcache/Optimizer/zend_optimizer.h b/ext/opcache/Optimizer/zend_optimizer.h index 04528d33e27..53f050d3f08 100644 --- a/ext/opcache/Optimizer/zend_optimizer.h +++ b/ext/opcache/Optimizer/zend_optimizer.h @@ -44,6 +44,8 @@ #define ZEND_OPTIMIZER_IGNORE_OVERLOADING (1<<16) /* (unsafe) Ignore possibility of operator overloading */ +#define ZEND_OPTIMIZER_NARROW_TO_DOUBLE (1<<17) /* try to narrow long constant assignments to double */ + #define ZEND_OPTIMIZER_ALL_PASSES 0x7FFFFFFF #define DEFAULT_OPTIMIZATION_LEVEL "0x7FFEBFFF" diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index a2d3e5caeb3..fe556b0546f 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -773,7 +773,8 @@ static int zend_jit_op_array_analyze2(const zend_op_array *op_array, zend_script && op_array->last_try_catch == 0 && !(op_array->fn_flags & ZEND_ACC_GENERATOR) && !(ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS)) { - if (zend_ssa_inference(&CG(arena), op_array, script, ssa, optimization_level) != SUCCESS) { + if (zend_ssa_inference(&CG(arena), op_array, script, ssa, + optimization_level & ~ZEND_OPTIMIZER_NARROW_TO_DOUBLE) != SUCCESS) { return FAILURE; } }