The world's largest retailer lifted its annual sales and profit forecast Tuesday as demand for groceries remained strong - with consumers turning to lower cost items like hotdogs, beans and peanut butter amid persistent inflation.

In the process, Walmart said it gained market share - its Chief Financial Officer telling Reuters that even higher earners looked to stretch their dollars further through cheaper items and sales events.

That allowed Walmart to also reduce its glut of inventory ahead of the holiday season.

The company also announced a new $20-billion share buyback plan, sending its shares up in morning trading to a six-month high.

Its results boosted stocks of other major retailers, including Target, Costco and Macy's.

Walmart's forecast for holiday quarter U.S. same-store sales, excluding fuel, however, fell below analysts' estimates.

Its CFO said consumers could slow spending, even in groceries, due to continued rising costs.

Walmart's comments follow those of FedEx and Amazon, which in recent weeks have also warned of muted holiday season demand.