* TSX ends down 3.46 points, or 0.02 percent, at 14,546.54
* Six of the TSX's 10 main groups finish lower
By Alastair Sharp
TORONTO, July 27 (Reuters) - Canada's main stock index closed barely lower on Wednesday, hurt by losses in energy shares as oil prices slid on a surprise inventory build, which offset positive comments from the U.S. Federal Reserve.
The Toronto Stock Exchange's S&P/TSX composite index ended the rollercoaster session down 3.46 points, or 0.02 percent, at 14,546.54.
It pared losses from early in the session after the Fed held rates steady and said the risks to its outlook had diminished.
"Clearly the headliner for today was the Fed and their policy statement, and that explains ... a little bit of the swings that we're seeing here late in the day," said Craig Fehr, Canadian market strategist at Edward Jones in St. Louis, Missouri.
The Canadian index turned lower earlier in the day as energy shares, a major component, were hurt by oil prices falling to three-month lows after the U.S. government reported a surprise build in crude and gasoline inventories during the peak summer driving season.
The heavyweight energy group, which had been trading higher before the inventory report was released, fell 1.6 percent, with Suncor Energy Inc down 1 percent at C$34.66 and Cenovus Energy Inc losing 3.1 percent to C$17.50.
Six of the index's 10 main groups were in negative territory, with decliners just barely outnumbering advancers.
The most influential gainers included grocery chain Loblaw Cos Ltd, which rose 3.7 percent to C$73.45, and technology company CGI Group Inc, which jumped 7.2 percent to C$63.05, after both beat earnings expectations.
"We are starting to see the makings of a little bit of an earnings rebound," Fehr said, adding that it was still early days in Canada's earnings season and that more evidence was required to justify the TSX's valuation.
Toronto Star publisher Torstar Corp fell 6 percent to C$1.56 after reporting a wider loss and cutting its dividend.
The materials group, which includes precious and base metals miners and fertilizer companies, jumped 2.8 percent as gold extended its climb above $1,330 an ounce after the Fed news..
Barrick Gold Corp surged 4.6 percent to C$28.22 and Goldcorp Inc jumped 3.1 percent to C$24.91.
Alaris Royalty Corp slumped 12.6 percent to C$25.64 after sharply missing earnings expectations and providing a weaker-than-expected outlook after markets closed on Tuesday.
Gildan Activewear Inc fell 5.6 percent to C$38.61 after reporting results and a weaker-than-expected outlook. (Reporting by Alastair Sharp; Editing by Jeffrey Hodgson and James Dalgleish)