This is the problem that Numba was designed to solve.
Numba is designed to speed up code where looping is unavoidable, i.e. the code can't be (easily) expressed as array OPs.
Do you have a source for this? I have not seen it in the numba docs.
If you want to look at the sort of things compilers do though, take a look at “common subexpression elimination”