merge common subexpressions and compile an expression