When GMRES is applied to a discrete ill-posed problem with a square matrix, then the iterates can be considered as regularized solutions. We show how to precondition GMRES in such a way that the iterations take into account a smoothing norm for the solution. This technique is well established for CGLS, but it does not apply directly to GMRES. We develop a similar technique that works for GMRES, without the need for modifications of the smoothing norm, and which preserves symmetry if the coefficient matrix is symmetric. We also discuss the efficient implementation of our algorithm, and we demonstrate its performance with numerical examples in 1D and 2D.