Function module for applying loop invariant optimisations