The S&P 500 index briefly surpassed its all-time record high on Thursday — the latest development in what has been a remarkable comeback from the precipice of a bear market.