Loop optimization plays an important role in compiler optimization and prog
ram transformation. Many sophisticated techniques such as loop-invariance c
ode motion, loop restructuring and loop fusion have been developed. This pa
per introduces a novel technique called loop quasi-invariance code motion.
It is a generalization of standard loop-invariance code motion, but based o
n loop quasi-invariance analysis. Loop quasi-invariance is similar iu stand
ard loop-invariance but allows for a finite number of iterations before com
putations in a loop become invariant. In this paper we define the notion of
loop quasi-invariance, present an algorithm for statically computing the o
ptimal unfolding length in While-programs and give a transformation method.
Our method carl increase the accuracy of program analyses and improve the
efficiency of programs by making loops smaller and faster. Our technique is
well-suited as supporting transformation in compilers, partial evaluators,
and other program transformers.