Wall Street's big gains this summer have been spread widely across industries. The profit growth helping to underpin those gains? Not so much.

Roughly 90% of the companies in the S&P 500 have reported their second quarter results, and their earnings per share are nearly 8% higher from year-ago levels in aggregate.

Along with market-buoying hopes that inflation may be close to a peak, that strong growth has helped the benchmark index jump roughly 15% since mid-June. A closer look shows investors are bidding up prices on all stocks, not just the ones with strong profits.

Energy companies, including Exxon Mobil and Chevron, saw their earnings nearly quadruple last quarter from a year earlier as prices soared for oil, gasoline and natural gas amid the worst inflation in 40 years.

Take out those companies, and earnings actually fell for the S&P 500, according to data from FactSet. Yet those non-energy stocks rose 9.1% from the end of June through Tuesday, slightly better than the 8.9% gain for the entire index.

Revenue is still rising for companies, because they are charging higher prices for their products and a strong jobs market has many customers in a position to keep buying. But for many businesses, their costs are rising even faster than revenue, which is cutting into their profitability.

While companies are still making a very high amount of profit off each $1 of revenue compared with history, their profit margins have come down a bit recently. It could get worse if inflation really is close to a peak and companies start ratcheting back on their own price increases.

The trend is clear when looking at the gap in inflation for prices that businesses are paying at the wholesale level versus what companies are charging at the consumer level, according to strategists at Morgan Stanley led by Michael Wilson. Wholesale inflation has never been this much higher than consumer price inflation, which "spells trouble for margins over the next several quarters," Wilson wrote in a recent report.

"Bottom line, earnings estimates remain too high in our view whether we have a recession or not," he said.

Stan Choe reports for the Associated Press.

Copyright 2022 AP. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.