Re:Circuit Transformations, Loop Fusion, and Inductive Proof
by rowanG077 on Friday April 17, 2026 @03:22AM
(#47803331)
Because two loops is really:
n*(x + c) + n*(y + c) => n*x + n*y + 2*n*c
Where c is some loop overhead, such as loading the arguments and work variables into registers and storing them back, checking the loop end condition, increasing the counters etc.
So if you fuse you get:
n*x + n*y + n*c
Honest question: why is that true? If x is the cost of running one iteration of the first loop and y is the cost for the second loop then the total cost is:
After fusing, the cost is: which is the same.