On Wed, Jun 1, 2016 at 8:24 PM, Dmitry Stogov <dmi...@zend.com> wrote:

> In the SSA optimisation framework  (part of opcache), we predict and
> propagate types of variables.
>
> We also may detect situations when some variables may be undefined.
>
> If variable can't be "undefined", we may avoid unnecessary run-time checks
> (e.g .like in ZEND_ADD_LONG handler).
>
> Local variables almost always initialized before usage, but with exiting
> behavior, function arguments always may be uninitialized.
>
To expand on this a bit... if a variable is potentially undefined, we
pretty much have to exclude it from optimization entirely, as nearly any
transformation we can make is prone to impact the undefined variable notice
in some way (remove, duplicate, reorder). The saving grace here is that
(untyped) function parameters don't have any type information, so we
typically can't apply transformations anyway (e.g. type specialization is
obviously not applicable, but many other transformation require guaranteed
warning/notice freedom, which usually requires more specific type
information than "any").

However, there are some optimizations that would be applicable if not for
the fact that the variable is potentially undefined. One such example is
copy propagation. Namely, in

function test($param) {
    $var = $param;
    // ...
    use($var);
}

we wouldn't be able to simply replace all uses of $var with $param and save
that assignment, because this might duplicate or reorder "undefined
variable" notices. Such "useless" variable-to-variable assignments are
typically introduced by inlining. (Note: Both copy propagation and inlining
are not currently in php-src, but may well be in the future.)

Nikita

Reply via email to