Peter Lynch once famously said that "everybody is a long-term investor until the market goes down." So when the market crashes, plenty of investors panic and hastily abandon their original plans for a holding a stock for decades until they retire. That panic selling often causes investors to miss out on some massive long-term gains, so it's generally a better idea to sit tight through downturns or buy more shares to reduce your average purchase price through dollar-cost averaging.

However, that strategy works only for well-run companies that are built to last for decades. I believe Nvidia (NVDA 6.18%) and ASML (ASML 2.04%) fit that description -- and that both stocks could be great long-term retirement plays.

A retired couple reviews their porfolio with a financial advisor.

Image source: Getty Images.

1. Nvidia

Nvidia is the world's top producer of gaming and data center GPUs. Its stock has already soared 12,270% over the past 10 years as the PC gaming and artificial intelligence (AI) markets expanded -- but it could still have room to run. Nvidia controls more than 80% of the discrete GPU market for high-end gaming, according to JPR, putting it far ahead of its largest competitor AMD. Nvidia also dominates the market for high-end GPUs in data centers -- where they're used to accelerate complex AI tasks. That's why all of the world's top AI platforms, including OpenAI's ChatGPT, currently use Nvidia's top-tier chips.

Analysts expect Nvidia's revenue and EPS to grow at compound annual growth rates (CAGRs) of 59% and 131%, respectively, from fiscal 2023 (which ended in Jan. 2023) to fiscal 2026. That breakneck growth should mainly be driven by the long-term expansion of the AI market, which Grand View Research expects to expand at a CAGR of 37% from 2023 to 2030, but its gaming business should also recover quickly as the PC market stabilizes.

Those growth rates look remarkable for a stock that trades at 27 times next year's earnings. However, Nvidia's stock is currently being held back by concerns regarding the new U.S. trade restrictions which are barring it from shipping its higher-end AI chips to China, as well as the development of first-party AI chips at top customers like OpenAI.

Those concerns are certainly valid, but I believe Nvidia can offset its lost sales in China with its growth in other markets. I also think it will take years, if not decades, for first-party chips to develop AI accelerator chips that can properly replace Nvidia's GPUs. Unless that happens, Nvidia will remain the top play on the growing gaming and AI markets.

2. ASML

Nvidia doesn't manufacture its own chips. It's a "fabless" chipmaker that outsources its production to third-party foundries such as Taiwan Semiconductor and Samsung. However, these foundries can't manufacture their smallest, densest, and most power-efficient chips without Dutch semiconductor equipment ASML (ASML 2.04%).

ASML is the world's leading producer of lithography systems, which are used to optically etch circuit patterns onto silicon wafers. It's also the world's only producer of top-tier extreme ultraviolet (EUV) lithography systems, which are used to manufacture the world's smallest chips down to the 2nm node. Its newest high-NA EUV systems will enable foundries to produce chips that are smaller than 2nm over the next few years.

ASML's monopolization of this crucial technology gives it incredible pricing power. The world's three most advanced foundries -- TSMC, Samsung, and Intel -- are all rushing to install more EUV and high-NA EUV systems to stay in the "process race" to produce more advanced chips. From 2022 to 2025, analysts expect ASML's revenue to grow at a CAGR of 16% as its EPS rises at a CAGR of 24%.

ASML's stock has already rallied more than 700% over the past 10 years and it isn't cheap at 35 times forward earnings. Its sales to China are also being throttled by the tightening trade restrictions, while new manufacturing technologies such as Canon's nanoimprint systems could potentially pry some foundries away from ASML.

Investors should certainly keep an eye on those long-term challenges, but I believe ASML's scale and dominance of the lithography market will ensure that it grows for decades to come. It might experience more macro headwinds and cyclical challenges, but it remains one of the best ways to profit from the secular expansion of the semiconductor market.