Shares of Lam Research (LRCX 2.65%) have been riding high in 2023 thanks to the surge in semiconductor stocks -- which may seem a tad surprising at first given the rate at which the semiconductor manufacturing equipment company's revenue and earnings declined in the past few quarters.

Specifically, Lam stock is up 57% in 2023, outpacing the 38% jump in the PHLX Semiconductor Sector index. The company released its fiscal 2023 fourth-quarter results (for the quarter ended June 25) last month, and the stock surged thanks to better-than-expected numbers. But a closer look at Lam's performance in the previous quarter and its near-term outlook suggest that the company's turnaround is still some time away.

Savvy investors, however, continue to pile into Lam stock despite the challenges the company faces due to weak spending on semiconductor equipment. Let's see why that's the case, and check why this semiconductor stock remains a solid long-term bet even after notching terrific gains so far this year.

Lam Research could soon witness an improvement in end-market conditions

Lam Research's revenue in the fourth quarter of fiscal 2023 fell a whopping 31% year over year to $3.2 billion. Adjusted earnings per share fell to $5.98 from $8.83 in the year-ago period. Analysts were anticipating a bigger decline, and would have settled for $5.07 per share in earnings on $3.13 billion in revenue.

The company's outlook, meanwhile, turned out to be well ahead of expectations. Lam anticipates fiscal 2024 first-quarter revenue of $3.4 billion at the midpoint of its guidance range, while non-GAAP earnings are expected to land at $6.05 per share. Wall Street was looking for earnings of $5.56 per share on $3.3 billion in revenue.

But it is worth noting that Lam's top and bottom lines will decline once again on a year-over-year basis in the current quarter. The company clocked just over $5 billion in revenue and $10.42 per share in adjusted earnings in the year-ago quarter. That means Lam anticipates a 32% decline in revenue and a 42% year-over-year drop in earnings in the current quarter, which isn't surprising considering the sharp pullback in semiconductor equipment spending this year, especially in the memory market.

Market research firm Gartner estimates that global spending on semiconductor manufacturing equipment could decline 22.5% this year, driven by the poor demand for smartphones and personal computers (PCs). Meanwhile, Lam Research estimates that the memory market could decline in the mid-40% range this year. The company gets 27% of its revenue from selling semiconductor manufacturing equipment to memory manufacturers, so it is not surprising to see that analysts are forecasting a sharp decline in the company's revenue in the current fiscal year.

Lam finished fiscal 2023 with $17.4 billion in revenue, a 1% drop over the prior fiscal year. The following chart indicates that a turnaround is expected from next year.

LRCX Revenue Estimates for Current Fiscal Year Chart

LRCX Revenue Estimates for Current Fiscal Year data by YCharts

However, it wouldn't be surprising to see a faster turnaround in Lam's fortunes, driven mainly by artificial intelligence (AI). The company estimates that semiconductor equipment spending is likely to improve from the second half of 2023, and AI could be one of the key catalysts. That's because, as Lam points out, AI servers are equipped with advanced processors, and need faster memory and more storage.

As a result, Lam says that a 1% increase in the adoption of AI servers in data centers requires an additional semiconductor capital investment of $1 billion to $1.5 billion. The adoption of AI servers is expected to grow rapidly. According to market research firm TrendForce, AI server shipments are set to jump 38% in 2023.

The firm estimates that AI server shipments could increase at an annual rate of 22% through 2026. Even then, there will be a lot of room for growth in AI server shipments, as they are estimated to account for 15% of the overall server market in 2026. The robust growth in AI server shipments will also create the need for more AI chips.

Gartner, on the other hand, forecasts that the AI chip market could more than double in revenue by 2027 to $119 billion, compared to $53 billion this year. All this indicates that Lam Research should be able to regain its mojo in the long run.

Why now is a good time to buy the stock

Lam Research stock trades at just 20 times trailing earnings right now, which is lower than the Nasdaq-100 Index's price-to-earnings ratio of 30. Buying the stock at this valuation could turn out to be a smart long-term move considering the catalysts discussed above, as well as the potential acceleration in the company's top line.

What's more, the company's earnings growth is also expected to step on the gas from the next fiscal year.

LRCX EPS Estimates for Current Fiscal Year Chart

LRCX EPS Estimates for Current Fiscal Year data by YCharts

Assuming Lam does hit annual earnings of $42.87 per share in fiscal 2026 and maintains its forward earnings multiple of 23 at that time, its stock price could hit $986. That would translate into 50% gains over the next three years, though it wouldn't be surprising to see Lam deliver even stronger gains because of catalysts like AI. As such, investors would do well to buy this semiconductor stock while it is still cheap.