ykjit / yk

yk packages
https://ykjit.github.io/yk/
Other
28 stars 7 forks source link

Optimise multiply chains #1245

Closed ltratt closed 1 month ago

ltratt commented 1 month ago

The main part of this commit is https://github.com/ykjit/yk/commit/0145e7ba45913a694052c9d4731b764a2e8be5fa, which allows us to optimise chains of multiplications of constants, but first of all I had to fix a "what was I thinking?" bug (https://github.com/ykjit/yk/commit/4209c61cb914eb83aaadc70dee9011328d2a1192).

ptersilie commented 1 month ago

Just a typo. I see that due to the structure of traces, this will naturally merge multiple (>2) multiplications despite the optimisation only looking at 2 at a time. However, I believe a mul without constants in the middle can block some merging, e.g.

%1 = %0 * 2;
%2 = %1 * %1;
%3 = %2 * 2;

which otherwise could be optimised to:

%2 = %1 * %1;
%3 = %2 * 4;
ltratt commented 1 month ago

However, I believe a mul without constants in the middle can block some merging, e.g.

Correct. I suspect we'll want to do a more clever tracking mechanism to spot such things, but we can get there bit-by-bit.

ptersilie commented 1 month ago

Please squash.

ltratt commented 1 month ago

Squashed.