[4.8] Backport loop and tree-vect related revisions

Backport of r196770, r197671, r198927,
r199620, r202088, r202229, r198333,
r198409, r199359, and r202049.