Compilers detect straight-forward examples but may not handle some examples obvious to humans.
for (i = 1; i <= N; ++i) x += f(y); becomes res = f(y); for (i = 1; i <= N; ++i) x += res;