Optimal invariant tests for the autocorrelation coefficient in linear regressions with stationary or nonstationary AR(1) errors