lua-users home
lua-l archive

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



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