Add basic common subexpression elimination for C++

This substantially reduces node count and speeds up compilation.
I didn't enable it for Verilog, since it does not appear to improve
synthesis results, but it does work if we choose to enable it later.