Oil prices jumped more than 3 percent after a surprisingly strong drawdown in gasoline stockpiles, pushing the U.S. benchmark back above $40 a barrel after falling from $50 in late June.

The Toronto Stock Exchange's S&P/TSX composite index <.GSPTSE> ended the session up 35.04 points, or 0.24 percent, at 14,512.05.

Its energy group, a major component, climbed 2.2 percent.

"We think it's the shorts that are driving the (oil) market lower," said Philip Petursson, chief investment strategist at Manulife Investments, referring to speculative bets that oil prices will fall. "Equity investors are looking through that to perhaps rising oil prices through the end of this year."

Suncor Energy Inc (>> Suncor Energy Inc.) gained 1.5 percent to C$34.56 and Canadian Natural Resources Ltd (>> Canadian Natural Resources Limited) rose 1.7 percent to C$39.43.

Husky Energy Inc (>> Husky Energy Inc.) advanced 6.9 percent to C$16.24. The company said it had reached agreement with China's CNOOC (>> CNOOC Ltd) over a gas project.

The materials group, which includes precious and base metals miners and fertilizer companies, lost 1 percent as the price of bullion fell from a three-week high hit in the previous session.

The most influential weights included Barrick Gold Corp (>> Barrick Gold Corp.), down 1.4 percent to C$29.32 and Kinross Gold Corp (>> Kinross Gold Corporation), off 1.9 percent at C$7.09.

The sector has in recent months helped to lessen the impact on the Canadian market of global shocks, including Britain's vote to leave the European Union, as investors back gold miners amid economic uncertainty.

Turquoise Hill Resources Ltd (>> Turquoise Hill Resources Ltd) fell 6.6 percent to C$4.25 after announcing quarterly results late on Tuesday.

Six of the index's 10 main groups were in positive territory, with gainers just outnumbering decliners.

Consumer staples rose 0.4 percent as dairy company Saputo Inc (>> Saputo Inc.) jumped 5.3 percent to C$41.84. Several analysts raised their price targets for the company's shares after it reported a profit jump, boosted its dividend, and said it remains interested in acquisitions.

Shares in Shopify Inc surged 9.3 percent to C$48.01 after the e-commerce software maker reported a smaller-than-expected quarterly loss and provided a more upbeat outlook.

(Reporting by Alastair Sharp; Editing by Paul Simao and James Dalgleish)

By Alastair Sharp