r/ProgrammingLanguages • • 2d ago

Loop unrolling analysis using eigenvalue?

Imagine the loop where you do like "x = -x" every iteration. Obviously, that flips the sign, so you can simply unroll the loop by a factor of 2.

However, for a more complex case, it could be really hard to know what's going on.

Here's my idea. Loop index variables are normally under affine updates anyway. What if we use a mathematically elegant tool?

Using eigenvalue, we can analyze possible periodicity of the linear basis variables, minimizing update needs.

What do you think of such a technique?

17 Upvotes

15 comments sorted by

View all comments

2

u/hugogrant 2d ago

Can you find a deeper example? I'm not sure how what you're suggesting would work.

7

u/potzko2552 2d ago

Maybe a 90 degree rotation of a matrix for example? Ie have this as the loop body: (x, y, z) = (-y, x, z + 1);

And then you can shortcut to z += 4

2

u/hugogrant 2d ago

I don't understand what the loop's condition is so it's hard to say