glsl2: Refactor constant folding of rvalues to a function.