3 ms·
Well, basically it's about converting iteratively computated state to a function of iteration count. Consider indvar[n] = indvar[n-1] + k, indvar[0] = a. It fo
by vnorilo 5y ago
Well, basically it's about converting iteratively computated state to a function of iteration count.
Consider indvar[n] = indvar[n-1] + k, indvar[0] = a. It follows that indvar[n] = a + n * k.
This is the type of indvar canonicalization that can zap loops such as the one in the article. Suddenly the final state is just a function of the loop trip count.
The return value is replaced with canonicalized indvar. That makes the loop itself dead (nobody observes any of its effects) and removed by subsequent dead code elimination pass.
My example transforms addition to multiplication. Another common one is multiplication into power. That's close to what's going on in the article example: xor is just a multiplication of signed one-bit integers.