The stock market is having a rough 2022 so far, and things could get worse if there is a recession. Analysts at Deutsche Bank estimate U.S. stocks could slide another 25% in value if a recession is declared.

In such a scenario, technology stocks would face even more pressure than they already do. The Nasdaq-100 Technology Sector index is down nearly 30% so far in 2022 and would likely fall much further in case of a recession. Evercore ISI analyst Amit Daryanani points out that more weakness could be in store for tech stocks considering how they performed in the 2008-09 Great Recession.

From a long-term investor's perspective, though, certain tech stocks have the potential to be great buys in a recession given their solid long-term prospects. Amazon (AMZN -1.65%) and Taiwan Semiconductor Manufacturing (TSM 2.71%), popularly known as TSMC, are two such tech companies that investors may want to buy if a recession hits and stock prices slide further. Let's see why.

1. Amazon

E-commerce and cloud giant Amazon's revenue grew by leaps and bounds in the years following the Great Recession. Amazon reported $24.5 billion in revenue in 2009. Last year, the company reported nearly $470 billion in revenue. That suggests a big-time bounceback.

This terrific growth at Amazon was driven by the growing adoption of e-commerce across the globe, the company's dominant position in major e-commerce markets, as well as its leadership in the fast-growing cloud computing market. The good part is that the e-commerce and cloud computing markets will continue to be major catalysts for Amazon in the long run and give the company's top and bottom lines a nice boost.

For instance, the global e-commerce market is forecast to clock 27% annual growth over the next five years, hitting $55 trillion in revenue in 2027 as compared to $13 trillion in 2022. Amazon controlled 13% of the e-commerce market share in 2020, which puts it in a nice position to record incremental revenue growth just from the secular opportunity it sits on. Consider too that global e-commerce revenue only totaled $550 billion in 2010.

Beyond e-commerce, the cloud services space will be another long-term growth driver for Amazon. That's because Amazon Web Services leads the cloud services market with a 34% market share, according to Synergy Research Group. The trailing-12-month revenue of the cloud services market stood at $200 billion at the end of the second quarter. The global cloud computing market could hit $750 billion in revenue by 2027, growing at an annual pace of 30% over the next five years. This presents another massive opportunity for Amazon to grow its business substantially in the coming years.

AMZN Revenue Estimates for Current Fiscal Year Chart

AMZN Revenue Estimates for Current Fiscal Year data by YCharts.

Not surprisingly, analysts expect the company's top line to grow steadily over the next few years. Analysts forecast 33% annual earnings growth at Amazon for the next five years.

Amazon's stock price is down 19% so far in 2022. Further weakness in the company's share price related to news of a recession could give investors a better entry point into Amazon stock. That's an opportunity savvy investors may not want to pass up given the company's sustained ability to deliver impressive growth.

2. Taiwan Semiconductor Manufacturing

TSMC is another tech giant that has come a long way since the previous recession. The semiconductor bellwether reported $9 billion in revenue in fiscal 2009. It finished fiscal 2021 with revenue of nearly $57 billion.

The company's terrific growth isn't surprising -- TSMC is the world's largest semiconductor foundry. In the first quarter of 2022, TSMC controlled 53% of the global semiconductor foundry space, which was way higher than No. 2 Samsung's share of 16%. The Taiwan-based company makes chips for the world's leading chipmakers and has an impressive client list.

TSMC benefited greatly from the rapid growth of the semiconductor market over the years. The global semiconductor market generated $195 billion in revenue in 2009, according to Gartner. That figure soared to $595 billion last year. By 2030, global semiconductor revenue is forecast to hit $1 trillion, according to McKinsey, indicating that the market is expected to add the next $400 billion in annual revenue at a much faster pace.

This should pave the way for impressive growth at TSMC. In fact, the company reported solid growth so far this year. TSMC reported a whopping 59% year-over-year jump in revenue in August 2022. The company's revenue has increased by 43.5% year over year in the first eight months of 2022. It is expected to finish the year with a 31% spike in revenue to nearly $75 billion. Even better, analysts expect an annual earnings growth rate of 23% from TSMC for the next five years.

All this indicates that TSMC is a no-brainer semiconductor stock to buy following its 31.7% price drop so far in 2022. The company is trading at 17 times trailing earnings and 14 times forward earnings. Both numbers are lower than its five-year average trailing earnings multiple of 23 and forward earnings multiple of 21.

So, investors can get their hands on TSMC stock at a much cheaper valuation in the event of a recession, and they should consider capitalizing on such an opportunity as this tech giant seems built for long-term upside.