Code cleanup: refactor the switch statements in the generation of reduction variables into an IR builder call.