The S&P 500 and Nasdaq Composite rose to fresh record highs on Wednesday, building on their rallies off the March lows, as tech shares led the way higher.