Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
}
}
break;

case ZEND_BOOL:
case ZEND_BOOL_NOT:
optimize_bool:
Expand Down Expand Up @@ -1800,6 +1800,7 @@ void zend_optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx)
}

/* Eliminate NOPs */
bool recompute_successors = false;
for (b = blocks; b < end; b++) {
if (b->flags & ZEND_BB_UNREACHABLE_FREE) {
/* In unreachable_free blocks only preserve loop var frees. */
Expand All @@ -1813,6 +1814,19 @@ void zend_optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx)
if (b->flags & (ZEND_BB_REACHABLE|ZEND_BB_UNREACHABLE_FREE)) {
strip_nops(op_array, b);
}
if (b->len == 0 && (b->flags & ZEND_BB_TARGET)) {
recompute_successors = true;
}
}
if (recompute_successors) {
for (b = blocks; b < end; b++) {
for (int s = 0; s < b->successors_count; s++) {
get_target_block(&cfg, b, s, &opt_count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that get_target_block() will update successors to a non-target block. I'm wondering if this could become an issue. Should we propagate the ZEND_BB_TARGET flag to the new successor?

Copy link
Member Author

@iluuu1994 iluuu1994 Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. get_target_block() should probably take care of that. Edit: Ah, I misunderstood. Yeah you're correct, this needs fixing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, that your previous fix relays on ZEND_BB_TARGET flag, that may be not accurately set for empty blocks and their followers. Updating it lazily in get_target_block() won't work for all cases.

}
if (b->len == 0 && (b->flags & ZEND_BB_TARGET)) {
b->flags &= ~ZEND_BB_TARGET;
}
}
}

opt_count = 0;
Expand Down
Loading