The S&P 500 hit an all-time high Wednesday, a remarkable turnaround for stocks while the war with Iran drives up energy prices and cuts into global growth.