The S&P 500 ended barely higher on Tuesday while the Nasdaq managed to scratch out a new record as gains in big tech names countered energy declines.

The Dow Jones Industrial Average also hit an intraday all-time high just after the market opened, and the benchmark S&P 500 came close to yet another record high.

U.S. equities have rallied sharply after President Donald Trump's election in November, spurred by hopes the Republican-led government will cut regulations and taxes and enact higher infrastructure spending.

However, investors have expressed concerns those polices could be put off as Trump focuses elsewhere such as on immigration.

"There is probably a bit of political risk that investors are trying to weigh right now," said Chuck Carlson, chief executive officer at Horizon Investment Services in Hammond, Indiana.

"But outside of that, the story is a pretty good one for stocks in terms of it looks like the economy is continuing to grow, I think corporate profits have been pretty good, certainly enough to support higher prices."

With more than half of the S&P 500 having reported results, fourth-quarter earnings are on track to have climbed 8.2 per cent, which would be the best performance since the third quarter of 2014, according to Thomson Reuters I/B/E/S.

The Dow Jones Industrial Average rose 37.87 points, or 0.19 per cent, to 20,090.29, the S&P 500 gained 0.52 points, or 0.02 per cent, to 2,293.08 and the Nasdaq Composite added 10.67 points, or 0.19 per cent, to 5,674.22.

Energy was the worst-performing S&P sector, falling 1.4 per cent. Chevron's 1.4-per-cent fall and Exxon's 0.6-per-cent drop were among the biggest drags on the S&P.

Oil prices were pressured by growing gasoline stockpiles in the United States as evidence of a burgeoning revival in U.S. shale production could complicate efforts to reduce a supply glut.

"If we are going into a quarter or two of lower energy prices ... the story of improving earnings for the S&P 500, with the help of improving earnings in energy companies, may be suspect," said Bucky Hellwig, senior vice president at BB&T Wealth Management in Birmingham, Alabama.

Tech stocks helped prop up the S&P. Apple rose about one per cent and Google parent Alphabet gained 0.9 per cent. Consumer staples were the best performing S&P group, rising 0.8 per cent.

In corporate earnings news, Emerson Electric shares rose 4.5 per cent after the manufacturer reported a higher-than-expected profit.

General Motors fell 4.7 per cent after the automaker said that fourth-quarter net income fell partly on the strength of the dollar against the British pound and forecast flat 2017 profit per share.

Michael Kors dropped 10.8 per cent, after the handbag maker forecast current-quarter profit below estimates.

After the market closed, Walt Disney shares fell following the company's quarterly report.

About 6.6 billion shares changed hands in U.S. exchanges, slightly below the 6.7 billion daily average over the last 20 sessions.

Declining issues outnumbered advancing ones on the NYSE by a 1.21-to-1 ratio; on Nasdaq, a 1.40-to-1 ratio favored decliners.

The S&P 500 posted 32 new 52-week highs and four new lows; the Nasdaq Composite recorded 108 new highs and 40 new lows.    

Canada's main stock index rose on Tuesday, with gains among heavyweight financial stocks on talk of a U.S. interest rate hike in March offsetting losses for shares of energy companies as oil prices weighed.

The Toronto Stock Exchange's S&P/TSX composite index settled up 41.86 points, or 0.27 percent, at 15,498.80. Nine of its 10 groups rose, although advancers only outnumbered decliners by a 1.2-to-1 ratio overall.

"We've got a broad-based rally but it doesn't have a huge velocity to it," said Peggy Bowie, a senior trader at Manulife Asset Management. "Volumes are light and the market is quiet."

She said Canadian financial stocks likely have more room to run as the prospect of higher interest rates from the U.S. Federal Reserve push bond yields up and support earnings growth.

Philadelphia Federal Reserve Bank President Patrick Harker said on Monday he was open to raising interest rates at the U.S. central bank's March policy meeting if growth in jobs and wages continued.

The most influential movers on the Canadian index included Bank of Nova Scotia, up 1.1 per cent at $79.06, and the country's biggest bank, Royal Bank of Canada, which rose 0.6 per cent to $95.28.

The financials group, which accounts for 35 per cent of the index's weight, gained 0.6 per cent overall.

The energy group fell 0.9 per cent as concerns about rising U.S. shale production weighed on crude oil prices.

Canadian Natural Resources Ltd lost 2.4 per cent to $37.99 and Encana Corp fell three per cent to $15.60.

Parex Resources Inc ended 3.1 per cent higher at $16.06 after the oil and gas company active in Canada and Colombia replaced its chief executive officer and said its proved plus probable reserves had grown 37 per cent.

Canada posted a second consecutive monthly trade surplus for the first time in more than two years in December, but booming oil exports obscured weakness in some key sectors.

Restaurant Brands International Inc advanced 2.7 per cent to $66 after the owner of the Burger King and Tim Hortons chains provided some 2016 earnings guidance ahead of its full release next week.

Westjet Airlines Ltd declined 2.5 per cent to $21.69 despite reporting a higher-than-expected quarterly profit.

Asanko Gold Inc slumped 12.4 per cent to $4.31 after analyst downgrade and Pretium Resources Inc fell 1.7 percent to $15.92 after it said its costs had increased as it moved to complete a speedier construction of its Brucejack mine.