Such determinations are a pretty common thing for an optimizing compiler to attempt:
http://en.wikipedia.org/wiki/Loop-invariant_code_motion
Such determinations are a pretty common thing for an optimizing compiler to attempt:
http://en.wikipedia.org/wiki/Loop-invariant_code_motion