Taiwan Semiconductor Manufacturing (TSM 1.60%), also known as TSMC, was down 42% in 2022 due to investor angst about high inflation and rising interest rates, fears of collapsing demand for chips, and legitimate concerns over what a global recession could mean for the business in 2023.

But despite the stock's decline in 2022, many investors have put it on their buy list for 2023. 

TSMC is a 'best in class' chipmaker

TSMC is the largest semiconductor contract manufacturer (or foundry) in the world. According to market research company TrendForce, TSMC grew its foundry market share to 56.1% in the third quarter of 2022, while in second place, Samsung's market share fell 10 basis points to 15.5%. 

Taiwan Semiconductor Manufacturing also displayed outstanding revenue growth of 35.9% year over year to $20.23 billion in the third quarter. But what elevates TSMC to greatness is its margins. According to current Intel CEO Pat Gelsinger, a "best in class" semiconductor company achieves gross margins in the 60% range and operating margins in the 40% range.

Despite terrible economic conditions, TSMC achieved those levels in the third quarter of 2022 by producing gross margins of 60.4%, beating its guidance for the quarter (between 57.5% and 59.5%) and exceeding year-ago gross margins of 51.3%. And operating margins during the quarter came in at an outstanding 50.6%, beating its guidance of 47% to 49% and exceeding year-ago results of 41.2%.

Historically, semiconductor companies that win the race to produce the smallest and most power-efficient chips gain premium pricing, more revenue, and the highest margins. TSMC is winning the race.

As chips get smaller and more complex, it requires more research and development and capital expenditure to produce chips capable of achieving premium pricing. And because the chip industry is cyclical, only the largest and most stable companies can afford the high price for investing in cutting-edge chips. So TSMC is one of the few companies on the bleeding edge for creating the smallest semiconductors, along with Samsung.

Weak smartphone demand in the first half of 2023 looms

TSMC derives over 40% of its revenue from the mobile phone market. And it gets an extra revenue boost because it is the sole supplier for the iPhone, and Apple is its largest customer.

So far, it has seen chip demand from the world's largest mobile phone manufacturer hold up during this downturn. For instance, Apple's stocking up with chips deployed in iPhone 14 models was why TSMC outperformed its peers in the third quarter of 2022.

TSMC's third quarter revenue by platform pie chart.

Image source: Taiwan Semiconductor Manufacturing.

Unfortunately, according to International Data Corporation, global smartphone shipments declined for the fifth consecutive quarter in the third quarter of 2022. This growth disease is already spreading to the previously immune Apple, with slowing iPhone demand in the period leading up to the holidays. And a zero-COVID-19 policy has reduced Apple's phone production in China.

Since most experts and industry insiders think the global smartphone market will only recover late in the second half of 2023, investors should refrain from counting on the mobile phone business to boost TSMC's results in the near term. As a result, you can expect the stock to be volatile over the next several quarters.

TSMC is a great long-term buy

TSMC is an attractive long-term investment because it benefits from the high demand for more and better semiconductors driven by the cloud, artificial intelligence, the Internet of Things, 5G, and high-performance computing -- trends that are decades-long growth opportunities.

The stock's price-to-earnings ratio has dropped from the first half of 2021 highs of 30-plus to today's 12.83, levels not seen since early 2017. And TSMC's price/earnings-to-growth (PEG) ratio is 0.62; most investors consider a PEG ratio below 1 a sign of an undervalued stock.

So if you are looking for a great company to invest in to start 2023, TSMC is an excellent long-term buy at the current price.