mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-12 13:00:38 +00:00
b5801d3377
This change folds: a * 1 => a a / 1 => a a * -1 => -a a / -1 => -a a * 2 => a + a a / 2^k => a * 2^-k a - 0 => a a + (-0) => a Note that the following folds are all invalid: a + 0 => a (breaks for negative zero) a - (-0) => a (breaks for negative zero) a - a => 0 (breaks for Inf/NaN) 0 - a => -a (breaks for negative zero) Various cases of UNM_NUM could be optimized (eg (-a) * (-b) = a * b), but that doesn't happen in benchmarks. While it would be possible to also fold inverse multiplications (k * v), these do not happen in benchmarks and rarely happen in bytecode due to type based optimizations. Maybe this can be improved with some sort of IR canonicalization in the future if necessary. I've considered moving some of these, like division strength reduction, to IR translation (as this is where POW is lowered presently) but it didn't seem better one way or the other. This change improves performance on some benchmarks, e.g. trig and voxelgen, and should be a strict uplift as it never generates more instructions or longer latency chains. On Apple M2, without division->multiplication optimization, both benchmarks see 0.1-0.2% uplift. Division optimization makes trig 3% faster; I expect the gains on X64 will be more muted, but on Apple this seems to allow loop iterations to overlap better by removing the division bottleneck. |
||
---|---|---|
.. | ||
apicalls.lua | ||
assert.lua | ||
attrib.lua | ||
basic.lua | ||
bitwise.lua | ||
buffers.lua | ||
calls.lua | ||
clear.lua | ||
closure.lua | ||
constructs.lua | ||
coroutine.lua | ||
coverage.lua | ||
datetime.lua | ||
debug.lua | ||
debugger.lua | ||
errors.lua | ||
events.lua | ||
exceptions.lua | ||
gc.lua | ||
ifelseexpr.lua | ||
interrupt.lua | ||
iter.lua | ||
literals.lua | ||
locals.lua | ||
math.lua | ||
move.lua | ||
native.lua | ||
native_types.lua | ||
native_userdata.lua | ||
ndebug_upvalues.lua | ||
pcall.lua | ||
pm.lua | ||
safeenv.lua | ||
sort.lua | ||
strconv.lua | ||
stringinterp.lua | ||
strings.lua | ||
tables.lua | ||
tmerror.lua | ||
tpack.lua | ||
types.lua | ||
userdata.lua | ||
utf8.lua | ||
vararg.lua | ||
vector.lua | ||
vector_library.lua |