luau/Compiler
Arseny Kapoulkine b1b21f395a
Compiler: Optimize k*n and k+n when types are known (#1529)
When type information is specified, we can compile k*n and k+n into
MULK/ADDK forms that are faster to execute, as long as we think n is a
number. Since we generally restrict type aware optimizations to O2, this
does that as well.

This makes trig benchmark ~4% faster on Apple M2 in VM, and also a tiny
improvement on scimark (~0.1%) can be observed. The optimization only
affects interpreted execution, as NCG already can synthesize optimal
code here.

If the type information is not truthful (e.g. user annotates type as a
number and it's not), the worst case scenario is flipped arguments to
metamethods like __add/__mul for constant left hand side.

Fixes #626 (the fix requires type information or NCG but I doubt any
further work on this is warranted)

---------

Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
2024-11-19 07:42:44 -08:00
..
include Sync to upstream/release/650 (#1502) 2024-11-01 12:06:07 -07:00
src Compiler: Optimize k*n and k+n when types are known (#1529) 2024-11-19 07:42:44 -08:00