Investing in artificial intelligence (AI) companies could be lucrative because no one really knows how far the technology will reach. But on the flip side, this technology might also fizzle out and not provide the returns investors are looking for.

There's one company that allows investors to succeed regardless of how the AI trend plays out: Taiwan Semiconductor Manufacturing (TSM 1.26%). And an investment could help you retire a millionaire someday. Read on to find out why TSMC could be a portfolio-defining investment.

Nearly all AI technology starts with TSMC's chips

Companies that want to train AI models rely on graphics processing units (GPUs) to constantly test and refine the platform using different data sets. And several sources are used to collect that data, which also requires GPUs. The company and the software developer also use the chips to train the model.

While there are multiple companies that sell GPUs, almost all of them source their chips from Taiwan Semiconductor.

As the leading contract chip manufacturer, TSMC is launching a smaller, more powerful, and more efficient version using 3-nanometer technology. This is sure to create a large market since it is currently the most powerful chip available.

As this next-generation 3nm technology is integrated into GPUs, companies will pay a premium to improve their speed and efficiency in training AI models. But even if AI turns out to be just another passing trend, the move to the cloud and processing big data aren't.

And TSMC's chips are also used in smartphones and other consumer products, so it's not as exposed to the AI market as some other investments. This makes it a more stable investment than its AI peers, but that doesn't mean the company is without its challenges.

Economic fear is hurting TSMC's results

The chip industry has long been plagued with cyclicality. As demand dries up for consumer electronics due to recession fears, it affects companies like Taiwan Semiconductor. It's experiencing that now, as revenue fell 13.7% year over year in U.S. dollars in the second quarter. This downturn is expected to worsen in the third quarter; management has guided for revenue between $16.7 billion and $17.5 billion, indicating a decline between 13.5% and 17.4%.

In the second quarter, TSMC's profit margin was 38%, down from 44% last year. This cut its earnings per share (EPS) from $1.55 to $1.14.

As a result of its current and future earnings drop, a forward price-to-earnings (P/E) ratio (which includes the decline) should be used in conjunction with the trailing P/E.

TSM PE Ratio Chart

TSM PE Ratio data by YCharts.

So, from a forward-looking perspective, the stock seems a bit pricey at a P/E over 20. But that outlook is fairly short-sighted. By 2024, the average Wall Street analyst projects $6.27 in EPS, indicating a forward P/E of 16.

For patient investors, Taiwan Semiconductor stock looks like an absolute bargain. Plus, with more products in the pipeline after the 3nm chip rollout, it's well positioned to maintain its market leadership.

Even if AI doesn't pan out as predicted, demand in data centers and smartphones won't disappoint. There are not a lot of guarantees in the stock market, but one that comes pretty close is that TSMC's cutting-edge chipmaking will drive next-generation technologies.