Reapply with r182909 with a fix to the calculation of the new indices for
insertelement instructions.