How good is Motoko optimizer?

Will Motoko optimizer eliminate calling f twice in:

let a = 2;
g(f(a));
h(f(a));

?

There is no such (function caching) optimization in any language that I know of. You need to set up this kind of memoization on your own.