[GIT-PULLS] [php-src] PR #23292: Compile negated conditions as inverted jumps
[email protected] (staabm)
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <[email protected]> |
Pull Request: https://github.com/php/php-src/pull/23292 Author: staabm disclaimer: this change was generated by claude opus. I have little experience with php-src development ---- 'if (!$x)', while/do-while conditions and ternaries with a top-level '!' emitted a BOOL_NOT into a temporary followed by JMPZ/JMPNZ - two dispatches and a TMP per evaluation, since without the opcache optimizer nothing rewrites it. Strip '!' layers in the condition and flip the jump opcode instead; both paths evaluate the operand with i_zend_is_true, so behavior including undefined-variable warnings is identical. This also lets comparisons under '!' fuse with the jump (smart branch), which BOOL_NOT previously prevented. Adjusts two opcode-dump tests for the changed temporary numbering. ---- note the improved `*_negated` variants after PR ``` ➜ php-src git:(negated-jumps) ✗ sapi/cli/php -n -d opcache.enable_cli=0 negated_conditions_repro.php PHP 8.6.0-dev ifIters=25000000 outer=80000 inner=64 rounds=5 case best(s) avg(s) sink ------------------------------------------------------ if_positive 0.157475 0.158927 0 if_negated 0.156479 0.159483 0 ternary_positive 0.170012 0.171106 0 ternary_negated 0.169497 0.171230 0 while_positive 0.016812 0.017440 0 while_negated 0.016239 0.016372 0 do_while_positive 0.016911 0.017201 0 do_while_negated 0.016190 0.016443 0 negated/positive ratios (best time, lower is better): if 0.9937x ternary 0.9970x while 0.9659x do_while 0.9574x ``` before PR ``` ➜ php-src git:(negated-jumps) ✗ sapi/cli/php_old -n -d opcache.enable_cli=0 negated_conditions_repro.php PHP 8.6.0-dev ifIters=25000000 outer=80000 inner=64 rounds=5 case best(s) avg(s) sink ------------------------------------------------------ if_positive 0.155232 0.156882 0 if_negated 0.166127 0.169627 0 ternary_positive 0.167289 0.168908 0 ternary_negated 0.178253 0.178780 0 while_positive 0.017045 0.017106 0 while_negated 0.020980 0.021447 0 do_while_positive 0.016768 0.016951 0 do_while_negated 0.020996 0.021222 0 negated/positive ratios (best time, lower is better): if 1.0702x ternary 1.0655x while 1.2308x do_while 1.2521x ``` using [negated_conditions_repro.php](https://gist.github.com/staabm/c5c89119edea93e6ad83833dc2568c26)