OK for trunk and for 4.7.
Committed as rev. 186213.
As a matter of curiosity, why did you not inhibit common function
extraction when the function arguments contain an implicit loop
variable, rather than when they are in an implicit loop? That would
make the optimisation rather less conservative.
The main reason was simplicity; it would have been necessary to keep
track of all the iterator variables (which can be nested) and check
if the function has any of them as arguments. Not impossible, but
I wanted this bug fix out of the door as soon as possible.
I have added a FIXME in the comment for this.
Thanks for the review!