Fix a bug in LinearFunctionTestReplace that created invalid loop exit checks.

Reviewed by Andy