legalize phi nodes