@@ -1304,6 +1304,9 @@ static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi)
1304
1304
ir_type type = (jit->ssa->var_info[phi->ssa_var].type & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE;
1305
1305
ir_ref merge = jit->bb_start_ref[phi->block];
1306
1306
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;
1307
1310
1308
1311
ZEND_ASSERT(phi->pi < 0);
1309
1312
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)
1320
1323
ZEND_ASSERT(jit->ra[src_var].ref);
1321
1324
if (jit->ra[src_var].ref == IR_NULL) {
1322
1325
jit->ra[src_var].flags |= ZREG_FORWARD;
1326
+ phi_inputs_are_the_same = 0;
1323
1327
} 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);
1325
1335
}
1326
1336
}
1337
+ if (phi_inputs_are_the_same) {
1338
+ ref = same_src_ref;
1339
+ jit->ctx.insns_count = old_insns_count;
1340
+ }
1327
1341
1328
1342
zend_jit_def_reg(jit, ZEND_ADDR_REG(dst_var), ref);
1329
1343
}
0 commit comments