IR: De-duplicate code for replacing operands in place

This is non-trivial and sits in three places.  Move it to
ConstantUniqueMap.