June 25 (Reuters) - The Nasdaq rallied on Tuesday, buoyed by strength in Nvidia and other tech megacaps, while the Dow slipped as retailers weighed and investors waited for crucial inflation data due out this week.

AI chip firm Nvidia rose sharply after a three-session sell-off and the broader chip sector outperformed with the Philadelphia Semiconductor index gaining ground.

Chips were among the biggest boosts for the S&P 500 technology index's recovery from a three-day slide while companies such as Alphabet and Meta Platforms supported the communication services index.

The rest of the S&P 500's 11 major industry sectors were much weaker by comparison on Tuesday in contrast with the prior day's session when previously lagging sectors such as energy and utilities were the biggest gainers.

"Seeing the tech stocks perking up has been a key driver" for Tuesday's market, said Emily Roland, co-chief investment strategist at John Hancock Investment Management. She added that after a few days of weakness, "investors that have scooped up some of those names today were looking for a better entry point."

Potentially adding to the bias for megacaps was the Conference Board's survey, which showed U.S. consumer confidence easing slightly in June amid worries about the economic outlook. Its consumer confidence index fell to 100.4 from a downwardly revised 101.3 in May.

"In an environment where economic growth is potentially decelerating, which we're seeing signs of, that would tend to benefit higher-quality stocks that have less sensitivity to the economic cycle," Roland said.

According to preliminary data, the S&P 500 gained 21.55 points, or 0.42%, to end at 5,469.42 points, while the Nasdaq Composite gained 220.84 points, or 1.26%, to 17,721.57. The Dow Jones Industrial Average fell 293.20 points, or 0.74%, to 39,118.01.

The Dow pulled back from a one-month high hit on Monday. Home improvement retailer Home Depot was among the Dow's biggest percentage decliners during the session.

Retail giant Walmart shares also fell after its CFO flagged the second quarter as the "most challenging quarter" at the NYSE 2024 European Investor Conference in London.

The Dow Jones Transport Average dropped after recent gains, with freight rail company Norfolk Southern among the weakest after a dimmer analyst view and a National Transportation Safety Board review of a derailment last year.

Transport heavyweight FedEx was due to report quarterly results after the close.

The most anticipated economic data due this week is the personal consumption expenditures (PCE) price index - the Fed's preferred inflation gauge - on Friday.

Spirit AeroSystems shares fell after a media report on Monday said Boeing offered to acquire the airplane fuselage maker in a deal funded mostly by stock that values its key supplier at about $35 per share. Boeing shares also fell.

Cruise operator Carnival Corp rallied after raising its annual profit forecast for the second time this year.

(Reporting by Sinéad Carew in New York, Ankika Biswas and Lisa Mattackal in Bengaluru Editing by Shounak Dasgupta, Maju Samuel and Matthew Lewis)