Add loop-invariant variable hoisting.

This is currently implemented as part of the constant folder for, er,
reasons.