Req #79337 [NEW]: optimize FETCH_CONSTANT

From: Date: Tue, 03 Mar 2020 11:16:58 +0000
Subject: Req #79337 [NEW]: optimize FETCH_CONSTANT
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225862@lists.php.net to get a copy of this message
From: bugreports at gmail dot com Operating system: PHP version: 7.4Git-2020-03-03 (Git) Package: opcache Bug Type: Feature/Change Request Bug description:optimize FETCH_CONSTANT Description: ------------ i would have expected that opcache optimizes the repeated FETCH_CONSTANT out --------------------------------- define('IS_ROBOT', 1); function a() { return IS_ROBOT . IS_ROBOT . IS_ROBOT . IS_ROBOT; } function b() { $IS_ROBOT = IS_ROBOT; return $IS_ROBOT . $IS_ROBOT . $IS_ROBOT . $IS_ROBOT; } --------------------------------- ************************************************************************************************************* * VLD OPCACHE * ************************************************************************************************************* function name: a number of ops: 8 ------------------------------------------------------------------------------------- 7 0* FETCH_CONSTANT ~1 'IS_ROBOT' 1* FETCH_CONSTANT ~2 'IS_ROBOT' 2* FAST_CONCAT ~0 ~1, ~2 3* FETCH_CONSTANT ~2 'IS_ROBOT' 4* FAST_CONCAT ~1 ~0, ~2 5* FETCH_CONSTANT ~2 'IS_ROBOT' 6* FAST_CONCAT ~0 ~1, ~2 7* RETURN ~0 function name: b number of ops: 5 ------------------------------------------------------------------------------------- 12 0* FETCH_CONSTANT !0 'IS_ROBOT' 13 1* FAST_CONCAT ~1 !0, !0 2* FAST_CONCAT ~2 ~1, !0 3* FAST_CONCAT ~1 ~2, !0 4* RETURN ~1 Expected result: ---------------- i would have expexted that repeatet FETCH_CONSTANT within a function is optimized out like the second implementation doing it in userland by copy it to a local variable not that much of a performance overhead but on the other hand if it's a function which a loop using dozens of constants more than once..... -- Edit bug report at https://bugs.php.net/bug.php?id=79337&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79337&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79337&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79337&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79337&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79337&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79337&r=support Expected behavior: https://bugs.php.net/fix.php?id=79337&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79337&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79337&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79337&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79337&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79337&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79337&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79337&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79337&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79337&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79337&r=mysqlcfg

« previous php.bugs (#225862) next »