Rising prices will inflate both revenue and cost, so even if margins don't actually improve, the actual amount of profit will rise due to inflation thus increasing stock value. Another way of looking at it is that, it's not necessarily the company that's doing better, but simply that paper money is losing value thus necessitating a rise in stock price even if the company value remains the same.