General Mills' (GIS 0.29%) stock rose to an all-time high on June 30 after the company posted its fourth-quarter earnings report. The packaged food giant's revenue rose 8% year over year to $4.89 billion, which beat analysts' estimates by $80 million, as its organic sales improved 13%. Its adjusted earnings increased 23% in constant currency terms to $1.12 per share, which also easily cleared the consensus forecast by 11 cents.

General Mills also provided a stable outlook for fiscal 2023, which started on May 30. It expects its organic sales to rise 4%-5% and for its adjusted earnings per share (EPS) to grow 0%-3% in constant currency terms.

A shopper pushes a shopping cart down a supermarket aisle.

Image source: Getty Images.

Those numbers probably wouldn't have impressed investors in a bull market, but they certainly look attractive in a bear market that favors defensive plays over pricier growth stocks. That's why General Mills' stock rose more than 10% this year as the S&P 500 declined about 20%.

Should investors still buy General Mills as a safe haven stock at these prices? Let's take a closer look at its business and valuations to find out.

Why is General Mills a recession-resistant play?

General Mills sells over 100 brands of packaged food products -- including Cheerios, Yoplait, Häagen-Dazs, Betty Crocker, Green Giant, and Pillsbury -- as well as premium pet food products through its Blue Buffalo subsidiary.

The current company was founded in 1928 and went public later that year. It's paid uninterrupted dividends every year since its founding -- even through the Great Depression, World War II, and over a dozen subsequent recessions.

General Mills continued to grow through those downturns because sales of consumer staples generally stay consistent throughout tougher times. It also repeatedly expanded by buying smaller brands, streamlined its business by divesting its weaker brands, and refreshed its classic brands with newer variations like Blueberry Cheerios and Yoplait Go-GURT.

That slow and steady growth enabled General Mills to generate a total return of 1,290% over the past 30 years after factoring in reinvested dividends. Past performance doesn't guarantee future gains, but its stable growth will likely continue for decades to come. That's why investors flocked to the stock as rising rates crushed the market's higher-growth stocks.

Can General Mills weather the inflationary headwinds?

General Mills is a recession-resistant stock, but inflation has still squeezed its margins over the past year with higher food and supply chain costs.

In fiscal 2022, its adjusted gross margin declined 180 basis points to 33% as those higher costs largely offset the benefits from its gradual price hikes and "Holistic Margin Management" (HMM) strategy -- which primarily focuses on cutting costs by installing energy-efficient technologies, optimizing its distribution networks, and reducing its packaging costs.

However, its operating margin still improved 100 basis points to 18.3% as it divested some of its weaker brands and paid lower restructuring expenses. Its adjusted operating profit rose 2% in constant currency terms.

In fiscal 2023, General Mills expects to face three main challenges: "the economic health of consumers, the inflationary cost environment, and the frequency and severity of disruptions in the supply chain." It plans to counter those near-term headwinds with more aggressive HMM cost-cutting strategies and additional price hikes. However, it expects the supply chain disruptions to "slowly moderate" in fiscal 2023.

General Mills' full-year guidance suggests it can weather those headwinds. In the meantime, it plans to convert "at least" 90% of its adjusted after-tax earnings to free cash flow (FCF) during the year, which it mainly plans to plow into buybacks and dividends. It intends to buy back about 2%-3% of its shares throughout fiscal 2023, which would surpass its long-term target for an annual share count reduction of 1%-2%.

Is General Mills' stock still undervalued?

Those confident buyback plans indicate General Mills believes its own shares are still undervalued. Its stock trades at 19 times forward earnings, which only makes it slightly pricier than those of industry peers like Kellogg (K 0.12%) and Kraft Heinz (KHC -0.88%), which trade at 18 and 14 times forward earnings, respectively. Kellogg and Kraft are also considered defensive plays, and both stocks have generated positive returns in this tough market this year.

General Mills pays a forward dividend yield of 2.9%, which is lower than Kraft's 4.2% yield and Kellogg's 3.2% yield -- but that's still more than double the S&P 500's current yield of about 1.4%.

I wouldn't consider General Mills to be a screaming bargain right now, but it still looks a lot cheaper than other traditional defensive plays like Procter & Gamble and Coca-Cola, which both trade at more than 20 times forward earnings. Therefore, it's still a good place to park your money in this volatile market -- but its upside potential will likely be limited by its valuation and the near-term concerns about inflation.