@@ -1304,6 +1304,9 @@ static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi)
13041304 ir_type type = (jit->ssa->var_info[phi->ssa_var].type & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE;
13051305 ir_ref merge = jit->bb_start_ref[phi->block];
13061306 ir_ref ref;
1307+ ir_ref old_insns_count = jit->ctx.insns_count;
1308+ ir_ref same_src_ref = IR_UNUSED;
1309+ bool phi_inputs_are_the_same = 1;
13071310
13081311 ZEND_ASSERT(phi->pi < 0);
13091312 ZEND_ASSERT(!(jit->ra[dst_var].flags & ZREG_LOAD));
@@ -1320,10 +1323,21 @@ static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi)
13201323 ZEND_ASSERT(jit->ra[src_var].ref);
13211324 if (jit->ra[src_var].ref == IR_NULL) {
13221325 jit->ra[src_var].flags |= ZREG_FORWARD;
1326+ phi_inputs_are_the_same = 0;
13231327 } else {
1324- ir_set_op(&jit->ctx, ref, i + 2, zend_jit_use_reg(jit, ZEND_ADDR_REG(src_var)));
1328+ ir_ref src_ref = zend_jit_use_reg(jit, ZEND_ADDR_REG(src_var));
1329+ if (i == 0) {
1330+ same_src_ref = src_ref;
1331+ } else if (same_src_ref != src_ref) {
1332+ phi_inputs_are_the_same = 0;
1333+ }
1334+ ir_set_op(&jit->ctx, ref, i + 2, src_ref);
13251335 }
13261336 }
1337+ if (phi_inputs_are_the_same) {
1338+ ref = same_src_ref;
1339+ jit->ctx.insns_count = old_insns_count;
1340+ }
13271341
13281342 zend_jit_def_reg(jit, ZEND_ADDR_REG(dst_var), ref);
13291343}
0 commit comments