Fix loop optimization in the presence of environment uses. am: 565cd4e986
am: 778188ffea

Change-Id: I0af7ba52700324ecd2c5e42976be4bc87e8d30bd