Legendary investor Peter Lynch once said, "When there's a war going on, don't buy the companies that are doing the fighting; buy the companies that sell the bullets." That advice can be applied to chipmakers. While numerous companies are fighting for control of end markets like cloud computing, consumer electronics, and electric cars, all of them depend heavily on semiconductors.

Building on that, Nvidia (NVDA 1.75%) and Taiwan Semiconductor Manufacturing (TSM -0.23%) have seen their share prices plunge 51% and 46%, respectively, but both stocks are well positioned to rebound when economic conditions improve and the next bull market thunders to life.

Here's what investors should know.

Nvidia: The leader in graphics and accelerated data center computing

Nvidia delivered a dismal third-quarter report. Revenue from its gaming and professional-visualization products plunged 51% and 65%, respectively, and data center sales growth decelerated sharply to 31%. Nvidia also booked a $702 million inventory charge related to weak data center demand in China. That write-down cut deeply into the bottom line. Putting all the pieces together shows total revenue falling 17% to $5.9 billion and earnings cratering 72% to $0.27 per diluted share.

Fortunately, there is a silver lining: The economic challenges will pass in time, and the bull case for Nvidia remains crystal clear. Its graphics processing units (GPUs) are the gold standard in rendering realistic visual effects and accelerating data center workloads like artificial intelligence (AI). In fact, Nvidia holds over 90% market share in workstation graphics and supercomputer accelerators, and the company has consistently set performance records at the MLPerf benchmarks, a biannual competition that measures the capabilities of AI hardware and software.

Better yet, Nvidia has continuously reinforced its superiority in graphics and data center computing through product innovation. For instance, Omniverse is a suite of subscription software that lets creators collaborate on 3D design projects and metaverse application development; it also serves as a simulation engine that helps engineers build AI models for self-driving cars and autonomous robots.

Similarly, Nvidia has broadened its data center product portfolio with high-performance networking solutions, server central processing units (CPUs), and subscription software for AI application development.

In a nutshell, Nvidia provides mission-critical computing technology with use cases across many large and growing industries, from manufacturing and logistics to retail and healthcare, and the company is well positioned to benefit as AI becomes more deeply engrained in daily life.

On that note, management values its addressable market at $1 trillion, leaving a long runway for growth. And with shares trading at 14.2 times sales -- a discount compared to the three-year average of 20.3 times sales -- now is a good time to buy this stock.

Taiwan Semiconductor: The leading chip manufacturer

Taiwan Semiconductor Manufacturing Company (TSMC) runs the largest foundry in the world, meaning it shoulders the cost-intensive burden of producing chips designed by other companies. In fact, TSMC has won the business of many popular technology companies, including consumer electronics giant Apple, high-performance computing specialist AMD, and Nvidia.

TSMC benefits from immense scale. It captured 56% market share in Q2, four times more than the next closest foundry, according to Counterpoint Research. That allows TSMC to invest more aggressively in product development, creating a flywheel that has consistently kept the company on the cutting edge of chipmaking technology. In fact, TSMC hopes to achieve volume production with its latest 3-nanometer process before the end of 2022, and management says it will be the "most advanced semiconductor technology" on the market.

Turning to financial performance, Q3 revenue climbed 36% to $20.2 billion, and earnings soared 66% to $1.79 per American depositary receipt. Those results are particularly impressive given the difficult economic conditions, and they reflect strong demand for Apple's new iPhone. However, management does expect inflation-fueled weakness in demand to weigh on its financial results through the first half of 2023, but those headwinds will ultimately be temporary.

On that note, the investment thesis for TSMC is straightforward: It is a critical link in the semiconductor supply chain, and its business should grow alongside industries like smartphones, high-performance computing, and the Internet of Things. Shares currently trade at 5.5 times sales, a discount to the three-year average of 9.7 times sales, which creates a reasonable buying opportunity for investors.