The stock market has been abysmal in 2022. The S&P 500 tumbled more than 20% during the first half of the year, its worst starting performance in 50 years. Red hot inflation -- fueled partly by surging energy costs -- has wreaked havoc on the stock market this year. 

However, while 2022 has been rough for most stocks, it has been a banner year for the oil patch. Several oil stocks have soared this year. Chevron (CVX 1.20%) and Devon Energy (DVN 0.58%) rallied more than 20% during the first half, while Occidental Petroleum (OXY 0.56%) was up over 100%. Here's a look at what fueled those big rallies and whether these oil stocks can continue outperforming in the second half.

A blistering rise in energy prices

Energy prices have skyrocketed this year. Oil prices soared 50%, pushing crude to over $100 a barrel. That drove prices at the pump to a record of over $5 a gallon in the U.S. Meanwhile, natural gas rocketed over 50% in the U.S. this year. 

Several factors created a perfect storm in the energy market, sending prices higher. Years of underinvestment in developing new oil and gas resources, made worse by the pandemic, left the world short of supply. On top of that, Russia invaded Ukraine, causing global governments to sanction one of the world's leading oil and gas producers, further impacting supply. This supply shock came amid soaring demand as pandemic-related restrictions rolled off, giving people more freedom to travel. 

A cash flow gusher for oil producers

Surging energy prices enabled oil and gas producers to reap a massive windfall. Oil giant Chevron generated $8.1 billion in cash flow from operations during the first quarter of 2022, nearly double its total in the same quarter of 2021. Meanwhile, Devon produced record-setting free cash flow of $1.3 billion in the quarter, while Occidental Petroleum also tallied record quarterly free cash flow of more than $3.3 billion. 

Occidental Petroleum used its windfall to repay $3.3 billion of debt, representing 12% of its outstanding principle. The oil company also announced a jaw-dropping 1,200% dividend increase and restarted its share repurchase program. The company's success caught the attention of investing legend Warren Buffett whose Berkshire Hathaway (BRK.A 0.99%) (BRK.B 0.91%) lifted its stake in the oil giant to 16.4%. 

Buffett's Berkshire Hathaway also boosted its stake in Chevron. Berkshire owned $25.9 billion shares of the oil giant at the end of the first quarter, a more than 400% increase from the end of 2021, pushing Chevron into a top-four holding. That will give Buffett's company even more dividend income, especially after Chevron increased its payout by 6% earlier this year. That marked the 35th straight year the Dividend Aristocrat has given its investors a raise. 

Speaking of dividends, Devon Energy has paid a gusher of them this year. The oil company has an innovative policy of paying a fixed base quarterly dividend that it compliments with a variable dividend of up to 50% of its excess cash each quarter. With its cash flow soaring, Devon has ramped up its dividend payments. It boosted its base payout by 45% this year. Meanwhile, its soaring variable payment has pushed its annualized dividend yield above 9%. 

Will oil stocks have the fuel to keep outperforming in the second half?

There's a lot of debate about where oil prices will go from here. On the one hand, the global economy appears to be teetering on the brink of recession, driven partly by surging energy prices. If there's an economic downturn, it could impact demand for refined petroleum products, which could weigh on oil prices. This potential for weaker demand is coming right as supplies could improve. OPEC recently agreed to add 648,000 barrels per day to the global supply starting in July. Further, the world continues to hold out hope that Russia will withdraw from Ukraine, which would take some pressure off the oil market. Because of that, crude prices could cool off in the second half. 

However, most analysts see the potential for more upside ahead. RBC Capital's global energy strategist Michel Tran called the current environment "the strongest fundamental oil market set up in decades, maybe ever." Tran further stated: "Absent a recession, the tightening cycle clearly points higher, potentially significantly higher. US$150/bbl, US$175/bbl, US$200/bbl? Pick a number." Even with a recession, Tran sees a multi-year cycle for the oil market. Many other analysts agree that oil will remain elevated. According to a recent poll by Reuters, analysts expect the global oil benchmark price to average $106.82 per barrel this year, a roughly $5 a barrel increase from their view in May. 

Given those supply and demand dynamics, the second half of 2022 will likely be very volatile in the oil patch. However, oil prices seem more likely to remain elevated than to cool off considerably. Because of that, oil stocks appear to have plenty of fuel left in the tank to continue rising. Warren Buffett certainly seems to agree with that assessment, given the money he poured into buying shares of Chevron and Occidental in the first half.