Every loop has a cost. When your program computes i * stride on each iteration, it pays for a multiplication — an operation that can be ten times slower than an addition on some hardware. Strength reduction is the compiler's answer: notice that the product only ever changes by a constant, then replace the multiply with an accumulating addition.
The idea is ancient by computing standards. Frances Allen and John Cocke described it in the early 1970s, but the pattern was already embedded in hand-optimised assembly of the 1960s. Yet it is not just a hardware trick — it is a precise algebraic observation: if and advances by 1 each step, then . One add replaces one multiply, every iteration, forever.
Strength reduction is one thread in a larger tapestry of program optimization ideas, and understanding it illuminates why compilers can often produce code that beats hand-written loops.
Comments
Loading comments...