IR: Factor out replaceUsesOfWithOnConstantImpl(), NFC

Factor out common code, and take advantage of the new function to
add early returns to the callers.