Status: New
Owner: ----
New issue 1507 by [email protected]: Generate short-circuit control flow for
&& and ||
http://code.google.com/p/v8/issues/detail?id=1507
There is a huge difference in code quality between f1 and f2:
function f1(x) { return x==100 || x==200 || x==300; }
function f2(x) { return !!(x==100 || x==200 || x==300); }
I see two ways to fix this and I would advocate for both:
First, the compiler should generate better control flow.
In both full-codegen and hydrogen
((a || b) || c)
is compiled as
(t2 = (t1 = a, t1 ? t1 : b), t2 ? t2 : c)
When t1 is true, the test on t2 is redundant.
This pattern would avoid a redundant test when 'a' is true:
t1 = a, t1 ? t1 : (t2 = b, t2 ? t2 : c)
The second way to fix the problem is do a general 'diamond busting'
optimization.
Generated code is full of chains of diamond control flow
(cond1 ? A : B);
(cond2 ? C : D);
If at A or B, cond2 is constant the test node cond2 can be short-circuited.
For example, if at B cond2 would be true, the optimization would make B
jump to or flow to C.
This optimization (does it have a formal name?) would mess up the dominator
structure of the control flow graph.
Attachments:
a6.js 0 bytes
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev