Hope for a U.S.-China trade deal diminished last month after both countries raised tariffs on billions of dollars worth of their goods. Trump also floated the possibility of imposing tariffs on more Chinese imports.

"Certainly, there's ground for optimism," said Michael Geraghty, equity strategist at Cornerstone Capital Group. "However, we have to remember there have been a lot of negotiations between China and the U.S. where they seem to be close to a deal and then things fell apart."

Boeing and Caterpillar shares, two trade bellwethers, rose 5.4% and 2.4%, respectively. Deere shares also gained more than 3%. Semiconductor stocks jumped on Trump's tweet. The VanEck Vector Semiconductor ETF (SMH) surged more than 4%, led by strong gains from Nvidia and Micron Technology.

Trump said in a tweet he " had a very good telephone conversation " with Xi. He added: "We will be having an extended meeting next week at the G-20 in Japan. Our respective teams will begin talks prior to our meeting." The summit will start on June 28.

The Dow Jones Industrial Average jumped 353.01 points to 26,465.54 as 3M and Boeing outperformed. The S&P 500 climbed 1% to 2,917.75 while the Nasdaq Composite advanced 1.4% to 7,953.88. The S&P 500 also closed 1.2% from its all-time intraday high of 2,954.13, which was reached May 1.

Stocks surged on Tuesday as Wall Street increased bets on a U.S.-China trade deal after President Donald Trump said he will be meeting with his Chinese counterpart, Xi Jinping, at the upcoming G-20 summit. Sentiment was also lifted by hope that the Fed will ease monetary policy later this year.

Tuesday's moves come as the Fed kicked off a key two-day monetary policy meeting.

The Fed is expected to leave rates unchanged. However, investors will monitor whether policymakers at the central bank lay the groundwork for rate cuts later in the year. Traders are pricing in three rate cuts before year-end, according to the CME Group's FedWatch tool.

"The market wants to hear words that err towards the Fed cutting rates in July," said Jennifer Ellison, principal at BOS. "If there's language that sounds like they're backing off from that, it's going to spook the market. Part of the reason the market is up today is because of the trade stuff, but also the anticipation around the Fed continuing to be very dovish."

The meeting comes after jobs growth and manufacturing activity in May slowed down. This, coupled with lingering worries over U.S.-China trade has led to increasing worries over the global economy.

The Fed's decision is scheduled to be announced Wednesday at 2 p.m. ET. Fed Chair Jerome Powell will also hold a news conference after the announcement.

"Short of easing tomorrow (about 20% priced in), Powell needs to send a strong enough message to the market" that rate cuts are coming, Gregory Faranello, head of U.S. rates at Amerivet Securities, said in a note. "I do feel, though, the Fed needs to take back some control here. We have gone from the market chasing the Fed (4 hikes) to the Fed chasing the market (3 cuts) in a very short period of time."

Investors also cheered the prospects of more stimulative measures from Europe. Mario Draghi, president of the European Central Bank, said Tuesday: "In the absence of improvement, such that the sustained return of inflation to our aim is threatened, additional stimulus will be required."

Draghi's comments sent the euro sliding against the dollar. They also jolted European stocks. The Stoxx 600 index climbed more than 1.5%, along with the German Dax and the French CAC 40.

Trump criticized Draghi's remarks, noting additional ECB stimulus makes it "unfairly easier" for Europe to compete with the U.S.

Stocks briefly fell from their highs after Bloomberg reported the White House was looking for legal ways to demote Powell from his spot at the Fed. Larry Kudlow, director of the National Economic Council, later said the president was not planning to demote Powell.

Stocks have been on fire this month, rebounding from steep losses in May. The major averages are all up more than 6% in June.

"There's really been two major drivers: the trade optimism and the optimism around interest rates," said James Ragan, director of wealth management at D.A. Davidson. "There are still headwinds out there. We'd feel better fading the rally a little bit. The market may be getting a bit ahead of itself in the short-run. But if we get through that meeting next week and there is a trade agreement and the Fed cuts rates, you could make the argument for a strong rally moving forward."

—CNBC's Sam Meredith contributed to this report.