encapsulate common instruction replacement pattern