Fix bound of gather loop

This should fix the bound of the gather loop for the host code generation (issue #326)