(Reuters) - Apple Inc shares rose nearly 5 percent on Wednesday, pushing the iPhone maker’s market valuation back toward $1 trillion as its quarterly report and upbeat forecast soothed investors worried about falling iPhone sales.

Slideshow ( 3 images )

Apple has been jockeying with Microsoft Corp and Amazon.com for the title of most valuable U.S. company as all three have passed the symbolic trillion mark.

The Cupertino, California, company first breached a trillion-dollar valuation in August last year. But it fell back as signs emerged of weak demand for its newest iPhones, especially in China, the world’s biggest smartphone market.

Apple’s shares ended 4.91% higher on Wednesday, valuing it at around $969 billion, based on shares outstanding as of April 22.

That left its stock market value ahead of Amazon and just behind Microsoft, with a market capitalization of $980 billion.

Though iPhone sales dropped 17% in the fiscal second quarter, the company’s services revenue beat Wall Street expectations and it forecast an upbeat third quarter.

Apple spent a record $24 billion on buybacks during the quarter. Its buybacks last year tmsnrt.rs/2vyr2oi topped $70 billion, or around five times its own spending on research and development.

At least eight brokerages hiked their price targets on the stock following Apple’s report, with Jefferies making the most aggressive move by raising its target by $50 to $210.

“Apple reported a clean March quarter and bullish June quarter outlook which against a backdrop of negative investor sentiment sets up for shares to move higher,” Morgan Stanley analysts said.

Analysts said iPhone demand in China was getting better as Apple cut prices, upgraded its device financing program and benefited from improved trade dialogue between the United States and China.

Twenty-one analysts recommend buying Apple’s stock, while 18 analysts are neutral and two recommend selling, according to Refinitiv data on Wednesday. Apple’s overall favorability among analysts puts it in line with American International Group and Berkshire Hathaway.

(GRAPHIC-Apple: R&D vs buybacks vs total cash link: tmsnrt.rs/2vyr2oi).

(GRAPHIC-Apple back in the $1 trillion race link: tmsnrt.rs/2ZQv8q2).