General Motors said it was writing down the value of battery and electric vehicle factories after changes in federal policy undercut demand.