The S&P 500 and the Nasdaq posted their best month since 2020 in April, as tech stocks drove gains boosted by the AI trade.