lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I suspect that the reasoning is:

* Things that can be evaluated statically could be handled by the developer.

* For almost everything else, the metatable semantics make optimization
almost impossible.

That said, I could see arguments for things like folding away the code in an
"if false" because this form might get used for turning code on and off.
That in turn perhaps argues for syntax for declaring constants in the code
that the compiler can then exploit as constants.

Mark

on 8/31/07 1:24 AM, David Jones at drj@pobox.com wrote:

> 
> On 30 Aug 2007, at 19:16, Patrick Donnelly wrote:
> 
>> I'm curious what kind of compiler optimizations Lua does when creating
>> the byte code, if any?
>> 
>> e.g.
>> 
>> x = 5 *  32 * i
>> 
>> becomes
>> 
>> x = 160 * i
>> 
>> internally.
> 
> Well, the answer is obviously going to vary a bit.  But the answer is
> approximately "almost none".
> 
> It does do (some) constant folding.  Constants are also pooled.  It
> mostly eliminates redundant branching in conditional forms.
> 
> No code-motion (but there's an opcode for for loops); no dead code
> elimination (the "if false" example you give); no common sub-
> expression elimination (in the presence of correctly preserving
> metatable semantics this wouldn't come up very often anyway); no
> strength reduction; no data-flow analysis.
> 
> drj