Add a 'switchify' optimization pass. Refs #1278.

Not sure what the protocol is regarding the addition of new optimizations. I've put it behind a flag for now, but initial tests look very positive, as mentioned in #1278.