Skip to content

Commit bfaf662

Browse files
committed
Micro-optimization
1 parent 9717a6d commit bfaf662

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

ext/opcache/Optimizer/block_pass.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,33 @@ static void strip_leading_nops(zend_op_array *op_array, zend_basic_block *b)
9292
{
9393
zend_op *opcodes = op_array->opcodes;
9494

95-
while (b->len > 0 && opcodes[b->start].opcode == ZEND_NOP) {
95+
do {
9696
/* check if NOP breaks incorrect smart branch */
9797
if (b->len == 2
98-
&& (op_array->opcodes[b->start + 1].opcode == ZEND_JMPZ
99-
|| op_array->opcodes[b->start + 1].opcode == ZEND_JMPNZ)
100-
&& (op_array->opcodes[b->start + 1].op1_type & (IS_CV|IS_CONST))
98+
&& (opcodes[b->start + 1].opcode == ZEND_JMPZ
99+
|| opcodes[b->start + 1].opcode == ZEND_JMPNZ)
100+
&& (opcodes[b->start + 1].op1_type & (IS_CV|IS_CONST))
101101
&& b->start > 0
102-
&& zend_is_smart_branch(op_array->opcodes + b->start - 1)) {
102+
&& zend_is_smart_branch(opcodes + b->start - 1)) {
103103
break;
104104
}
105105
b->start++;
106106
b->len--;
107-
}
107+
} while (b->len > 0 && opcodes[b->start].opcode == ZEND_NOP);
108108
}
109109

110110
static void strip_nops(zend_op_array *op_array, zend_basic_block *b)
111111
{
112112
uint32_t i, j;
113113

114-
strip_leading_nops(op_array, b);
115114
if (b->len == 0) {
116115
return;
117116
}
118117

118+
if (op_array->opcodes[b->start].opcode == ZEND_NOP) {
119+
strip_leading_nops(op_array, b);
120+
}
121+
119122
/* strip the inside NOPs */
120123
i = j = b->start + 1;
121124
while (i < b->start + b->len) {
@@ -168,8 +171,14 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
168171
zend_op *opline, *src;
169172
zend_op *end, *last_op = NULL;
170173

171-
/* remove leading NOPs */
172-
strip_leading_nops(op_array, block);
174+
if (block->len == 0) {
175+
return;
176+
}
177+
178+
if (op_array->opcodes[block->start].opcode == ZEND_NOP) {
179+
/* remove leading NOPs */
180+
strip_leading_nops(op_array, block);
181+
}
173182

174183
opline = op_array->opcodes + block->start;
175184
end = opline + block->len;

0 commit comments

Comments
 (0)