Taiwan Semiconductor Manufacturing (TSM -0.37%) and ASML (ASML 3.73%) are two of the most important semiconductor companies in the world.

TSMC, which is based in Taiwan, is the world's most advanced contract chipmaker. Major chipmakers like AMD, NVIDIA, and Apple (NASDAQ: AAPL) all rely on TSMC to produce their smallest and most powerful chips. Even Intel, which traditionally manufactures its own chips, has started outsourcing some of its chips to TSMC.

ASML, which is based in the Netherlands, is the world's top producer of lithography machines. These machines are used to etch circuit patterns into silicon wafers; chip foundries like TSMC use ASML's top-tier EUV (extreme ultraviolet) machines to manufacture their smallest chips. 

A futuristic illustration of a glowing chip.

Image source: Getty Images.

The global semiconductor market can't keep running without these two companies. Shares of TSMC and ASML have more than doubled over the past 12 months amid surging chip sales, and the ongoing global chip shortage could propel both stocks even higher. But which stock is the better overall investment right now?

The symbiotic relationship between TSMC and ASML

ASML generated 34% of its revenue from Taiwan last year. Its largest customer was TSMC, which accounted for 31% of its top line.

TSMC uses ASML's newest multi-patterning EUV machines to manufacture its newest 5nm and 7nm chips. ASML plans to launch more advanced EUV systems, called high-NA systems, to manufacture even smaller 3nm to 2nm chips between 2022 and 2025.

TSMC plans to increase its capex by up to 63% this year to upgrade its equipment and maintain its lead in the "process race" to produce smaller and more powerful chips. Its main rival, Samsung, and other South Korean chipmakers could also increase their average capex by over 20% this year.

A lot of that cash could be spent on ASML's EUV machines. Therefore, the current global shortage could squeeze TSMC's margins, but generate strong tailwinds for ASML's core business.

Which company is growing faster?

TSMC generated 41% of its revenue from its newest 5nm and 7nm nodes in 2020. In terms of end markets, it generated 48% of its sales from the smartphone market, 33% from the HPC (high-performance computing market), and the rest from other industries.

TSMC's largest customer is Apple, which likely accounted for 25% of its revenue last year. Apple could account for over half of TSMC's 5nm production this year, according to Counterpoint Research.

ASML's EUV machine.

Image source: ASML.

TSMC's revenue rose 25% (31% in USD terms) for the full year, and its earnings per share jumped 50%. Analysts expect its revenue and earnings to rise 21% and 16%, respectively, in USD terms this year.  The global chip shortage should consistently drive its revenue growth, but its higher capex could squeeze its margins.

ASML generated 43% of its total system revenue from its top-tier EUV systems in 2020. The segment's revenue rose 59% during the year as the world's top foundries upgraded their hardware. It shipped its 100th EUV system in the fourth quarter, and 26 million wafers had been exposed to its EUV machines by the end of the year.

ASML's gross margins have consistently expanded over the past several years as it sells its newer systems at ever-higher margins. As a result, its revenue and net income rose 18% and 37%, respectively, in 2020. Analysts expect its revenue to rise 33% this year, with 40% earnings growth.

The valuations, dividends, and verdict

TSMC trades at 26 times forward earnings, which is much lower than ASML's forward P/E ratio of 45. TSMC's forward dividend yield of 1.5% is also three times higher than ASML's forward yield of 0.5%.

TSMC and ASML are both solid long-term investments in the semiconductor market. But if I had to choose one over the other, I'd buy ASML, because TSMC and its rivals all need to buy its EUV systems -- which makes it a more diversified and balanced play on the semiconductor sector.

TSMC must keep increasing its capex to retain its lead in the process race, and a lot of that spending will flow to ASML and other semiconductor equipment companies while squeezing its own margins. That's why TSMC trades at lower multiple than ASML, and why it's a slightly less compelling investment right now.