Cse rewrite

A rewrite of common-subexpression-elimination. The old version was pretty flaky.
Surely this will trigger unreachable-code warnings.