S&P 500 posts best day in 3 weeks as US stocks close higher