Alternative code motion algorithm and tests for it.

Less efficient than it could be (rebuild is quadratic at the moment), and shares too many subexpressions, which I'm going to fix when I have time.