Skip to content

Commit e8525c2

Browse files
TysonAndredstogov
authored andcommitted
Optimize int === int/double === double
Do this by reusing the implementation used for `==` when both arguments are ints (IS_LONG) or both are floats (IS_DOUBLE) ```php // Before: nestedloop_ni took 0.442 seconds // After: nestedloop_ni takes 0.401 seconds (same as nestedloop_ne) function nestedloop_ni(int $k) { $x = 0; for ($i=0; $i < 50000000; $i++) { if ($i === $k) { $x++; } } print "$x\n"; } function nestedloop_ne(int $k) { $x = 0; for ($i=0; $i < 50000000; $i++) { if ($i == $k) { $x++; } } print "$x\n"; } ```
1 parent 17a021e commit e8525c2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Zend/zend_vm_execute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59194,6 +59194,7 @@ ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler_ex(zend_op* op, uint32_t
5919459194
}
5919559195
break;
5919659196
case ZEND_IS_EQUAL:
59197+
case ZEND_IS_IDENTICAL:
5919759198
if (op->op1_type < op->op2_type) {
5919859199
zend_swap_operands(op);
5919959200
}
@@ -59210,6 +59211,7 @@ ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler_ex(zend_op* op, uint32_t
5921059211
}
5921159212
break;
5921259213
case ZEND_IS_NOT_EQUAL:
59214+
case ZEND_IS_NOT_IDENTICAL:
5921359215
if (op->op1_type < op->op2_type) {
5921459216
zend_swap_operands(op);
5921559217
}
@@ -59330,8 +59332,6 @@ ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler_ex(zend_op* op, uint32_t
5933059332
case ZEND_BW_AND:
5933159333
case ZEND_BW_XOR:
5933259334
case ZEND_BOOL_XOR:
59333-
case ZEND_IS_IDENTICAL:
59334-
case ZEND_IS_NOT_IDENTICAL:
5933559335
if (op->op1_type < op->op2_type) {
5933659336
zend_swap_operands(op);
5933759337
}

Zend/zend_vm_gen.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,13 @@ function gen_vm($def, $skel) {
28182818
if (isset($dsc['type_spec'])) {
28192819
$orig_op = $dsc['op'];
28202820
out($f, "\t\tcase $orig_op:\n");
2821+
// XXX: Copy the specializations for LONG == LONG and DOUBLE != DOUBLE to work for ===/!== as well.
2822+
// (Those are currently the only specializations)
2823+
if ($orig_op === 'ZEND_IS_EQUAL') {
2824+
out($f, "\t\tcase ZEND_IS_IDENTICAL:\n");
2825+
} elseif ($orig_op === 'ZEND_IS_NOT_EQUAL') {
2826+
out($f, "\t\tcase ZEND_IS_NOT_IDENTICAL:\n");
2827+
}
28212828
if (isset($dsc["spec"]["COMMUTATIVE"])) {
28222829
out($f, "\t\t\tif (op->op1_type < op->op2_type) {\n");
28232830
out($f, "\t\t\t\tzend_swap_operands(op);\n");
@@ -2857,8 +2864,10 @@ function gen_vm($def, $skel) {
28572864
!isset($dsc['type_spec']) &&
28582865
isset($dsc["spec"]["COMMUTATIVE"])) {
28592866
$orig_op = $dsc['op'];
2860-
out($f, "\t\tcase $orig_op:\n");
2861-
$has_commutative = true;
2867+
if (!in_array($orig_op, ['ZEND_IS_IDENTICAL', 'ZEND_IS_NOT_IDENTICAL'])) {
2868+
out($f, "\t\tcase $orig_op:\n");
2869+
$has_commutative = true;
2870+
}
28622871
}
28632872
}
28642873
if ($has_commutative) {

0 commit comments

Comments
 (0)