Optimize IterInit[K] and IterNext[K] in HHBBC better (take 2)
commit5727687b8c6fd9d34b1069fc677577288de0b4ba
authorRick Lavoie <rlavoie@fb.com>
Mon, 11 Sep 2017 23:46:32 +0000 (11 16:46 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 12 Sep 2017 00:03:43 +0000 (11 17:03 -0700)
treebbcdeaf4a8118103236c5bc2e52262922d1afcf7
parentce1ed4529f7f3e4c064218f57938c262c43ebad9
Optimize IterInit[K] and IterNext[K] in HHBBC better (take 2)

Summary:
Do a better analysis of things being iterated over to enable better
optimizations of IterInit[K] and IterNext[K]. Namely, if we definitely know we
won't enter the iteration loop (for example, if the input array is known to be
empty, or something that isn't an array), we can mark the loop body as
unreachable and not consider its effects. Likewise, if we know we'll always
enter the iteration loop (for example, if the input array is known to be
non-empty), we can consider IterInit's fallthrough case to be unreachable. If we
know the thing being iterated over is an array that's not bigger than one
element, we can optimize away an IterNext into just an IterFree with
fall-through (because it will never loop).

This is the second take on this diff, adding back the logic to merge together
iterator state.

Reviewed By: markw65

Differential Revision: D5805619

fbshipit-source-id: 6dc4c71819cf84b1356ff049bcc3478781dd55bc
hphp/hhbbc/interp-state.cpp
hphp/hhbbc/interp-state.h
hphp/hhbbc/interp.cpp
hphp/hhbbc/optimize.cpp
hphp/hhbbc/type-system.cpp
hphp/hhbbc/type-system.h
hphp/test/slow/hhbbc/iteration.php [new file with mode: 0644]
hphp/test/slow/hhbbc/iteration.php.expectf [new file with mode: 0644]