U.S. stocks notched solid gains Wednesday, recouping some of the market's losses from a day earlier.

Technology and health care companies drove much of the rebound, outweighing losses in safe-play stocks like utilities and real estate investment trusts. Small-company stocks fared better than the rest of the market.

Macy's led a rally among retailers after reporting surprisingly strong results, adding to the strong wave of corporate earnings in recent weeks.

"Earnings growth has shown through and that's been primarily based on strong fundamental growth from U.S. companies," said Jamie Lavin, global investment specialist at J.P. Morgan Private Bank. "And when equity markets are able to look through to that and we don't have any major geopolitical headlines, we tend to have stronger days in the market."

The S&P 500 index rose 11.01 points, or 0.4 percent, to 2,722.46. The Dow Jones industrial average gained 62.52 points, or 0.3 percent, to 24,768.93. The increase nudged the 30-company average to a small gain for the year.

The Nasdaq composite added 46.67 points, or 0.6 percent, to 7,398.30. The Russell 2000 index of smaller-company stocks picked up 16.03 points, or 1 percent, to 1,616.37, topping its last all-time high in January.

Major indexes in Europe also finished higher Wednesday.