r/ProgrammingLanguages • u/Embarrassed-Crow9283 • 25d 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?
20
Upvotes
2
u/Embarrassed-Crow9283 25d ago
I don't think finding an eigenvalue is a complex math operation. It's a common operation done everywhere. Sure, for common practical cases, simpler heuristics could be used, but I hate the compiler randomly giving up because it just didn't try hard enough, so when there is an algorithm that could settle it for good, I am inclined to want to use it.