Stocks extended gains on Tuesday as optimism over a confidence vote for Greece and better-than-expected housing data boosted investor appetite for equities.

Expectations that a default of Greek debt could be avoided supported the market for a second day. Consensus grew that Prime Minister George Papandreou would survive a confidence vote in Greece's parliament, easing fears about the euro zone debt crisis that have weighed on the market for months.

So far it looks like people are expecting a positive outcome from that. If it doesn't go that way, it's anybody's guess how much downside there could be, said Tom Donino, co-head of trading at First New York Securities in New York.

Adding to the positive sentiment, sales of existing homes fell to a six-month low in May, but the decline was less than expected.

The Dow Jones industrial average <.DJI> put on 80.23 points, or 0.66 percent, at 12,160.61. The Standard & Poor's 500 Index <.SPX> advanced 13.39 points, or 1.05 percent, at 1,291.75. The Nasdaq Composite Index <.IXIC> jumped 43.25 points, or 1.64 percent, at 2,672.91.

After nearing its 200-day moving average in the previous session, the S&P 500 rebounded solidly above the level. Analysts identified 1,360 as the next technical level to watch for.

In company news, U.S.-traded shares of Research In Motion Ltd rose 5.3 percent to $27.25 after falling about 7 percent on Monday. A second marketing executive defected to a competitor, highlighting its difficulties in keeping pace with rivals.

Also supporting the Nasdaq, Apple Inc was up 2.5 percent at $323.38.

But Walgreen Co fell 5.7 percent to $42.61 after the drugstore chain reported higher quarterly earnings but said efforts to renew a deal with pharmacy benefits manager Express Scripts Inc had failed.

Barnes & Noble Inc , the No. 1 bookstore chain, reported a deeper quarterly loss as sales came under pressure from going-out-of-business sales at rival Borders Group Inc. The stock dipped 0.5 percent at $20.05.

The Greek confidence vote, a key hurdle the government must clear to avert the euro zone's first sovereign debt default, was due around 5 p.m. EDT (2100 GMT).

The Federal Open Market Committee begins a two-day meeting, with an announcement expected Wednesday afternoon, followed by a new conference with Federal Reserve Chairman Ben Bernanke. The Fed is expected to cut its growth forecast for 2011, but Bernanke will likely continue to argue the slowdown is temporary.

(Reporting by Angela Moon; editing by Jeffrey Benkoe)