Investors reeling from several quarters of declines from U.S. energy companies are optimistic that a recent oil rebound may help boost results of E&Ps reporting in the coming days.

After a nearly two-year slide in crude, higher oil prices may lead to higher production this year and in 2017, investors believe. However, a lot depends on whether the big rally in oil prices from February lows has run its course.

U.S. oil prices, trading around $42 a barrel, are back at April levels after jumping 26.1% in the second quarter, their best quarterly gain since 2009.

Shares of E&Ps have done well this year, with gains of 11.2% in the S&P oil and gas E&P index since Dec. 31 compared with a 6% rise in the S&P 500.

"The big question of course is oil prices," said Mike Breard, analyst at Hodges Capital Management in Dallas. "The main thing people should look at when these companies report second-quarter earnings is if they're going to add wells or do something to increase production in the second half of the year and in 2017."

Second-quarter earnings for the S&P 500 energy sector, though still forecast down 77.7% from a year ago, are expected to have improved from the first quarter, when profits fell 105.7%—seen as the bottom of the current energy sector profit downturn, Thomson Reuters data shows.

Independent E&P companies such as Apache Corp. (NYSE: APA) and Devon Energy Corp. (NYSE: DVN), both of which are due to report results next week, may benefit the most from better oil prices, while the impact on integrated oil majors including ExxonMobil (NYSE: XOM) and Chevron Corp. (NYSE: CVX), due to report July 29, may be more mixed.

"The big oil companies are so diversified and hedged that we're unlikely to see a big surprise from them one way or the other," said Tim Ghriskey, chief investment officer of asset management company Solaris Group in Bedford Hills, N.Y., which is overweight energy.

Overseas, BP Plc's (NYSE: BP) earnings on July 26 missed expectations and its shares fell even though it said it would pursue three new projects this year.

RELATED: BP To Pursue New Projects Despite Earnings Miss

ExxonMobil shares are up 16.6% in 2016, while Chevron is up 13.7%.

Early results from U.S. companies have been mixed. Anadarko Petroleum (NYSE: APC) and Hess Corp. (NYSE: HES) this week reported smaller-than-expected quarterly losses, though Hess further cut its E&P budget for the year.

RELATED: Anadarko Survives Rough Ride In Second Quarter

For refiners, the outlook remains grim. Profits are expected to slide for a third straight quarter and lower crude volumes are seen hitting margins.

The S&P oil and gas refining and marketing index is down 20.2% for the year so far.

"The performance is largely explained by a disappointing gasoline market," Cowen and Co. analysts wrote in a recent note. "Gasoline margins are now expected to be lower year over year, and upside risk is uncertain."