Investors buy dividend stocks for many different reasons. Some choose to own dividend stocks because they typically represent more financially stable companies. Some choose dividend stocks to help provide steady income as they near retirement. Many investors love dividend stocks simply because of the long-term power of compounding.

Whatever the reason, any dividend investor loves when they find a valuable dividend in an unloved company, because a stock price with upside and a dividend on top of that is an enticing opportunity. Here are two stocks currently hated by the market that may offer that exact opportunity for investors.

General Motors (NYSE:GM)
Considering the types of publicity General Motors has had over the past few years, it's not surprising to many that the stock is unloved. First, you have the automaker's massive and tragic ignition switch recall that covered roughly 30 million vehicles worldwide. In addition to that, you have the current concerns of rising subprime loans in the auto industry and fears of new vehicle sales peaking in the automaker's U.S. profit engine.

GM has recovered from its plethora of vehicle recalls, and while headlines tout subprime as a negative, it doesn't apply to Detroit's largest automaker. Just look at the percentage of GM's subprime loans of its total.

Chart by author. Information source: General Motors Financial.

While subprime loans may be increasing in total volume across the industry, it's certainly not an issue for GM investors. Furthermore, while many investors are worried about automotive sales peaking in the U.S., there are many factors that suggest sales figures will remain at very strong levels for years.

Consider that the age of the U.S. fleet is a record high 11.5 years, credit is still easily available and cheap, low fuel prices are putting extra cash in consumers' wallets, and automakers themselves are more efficient with lower breakeven levels than in the past decade. Heck, on top of that, household finances are improving and so is the U.S. labor market.

GM is a much healthier automaker than in years past, and the market appears poised to support high levels of vehicle sales for the foreseeable future. GM recently increased its quarterly dividend by 6% to $0.38, which equates to a nearly 5% yield, and boosted its share buyback program by $4 billion. While GM may be an unloved stock, it looks like a great opportunity with upside for dividend investors.

If you're looking for a beaten-down industry, look no further than the railroad industry since the beginning of 2015. It's been painful for investors.

CSX Chart
CSX data by YCharts.

Last year was one of the worst for railroad stocks in quite some time thanks to significant declines in the price of oil and coal, which have historically made up a high number of carloads for railroad companies. But the railroad industry has significant barriers of entry, and for that reason, these companies aren't going anywhere and investors buying during rough patches like these will almost certainly benefit in the future.

Meanwhile, despite recent woes, CSX Corp. has done an incredible job of improving its margins over the past decade. The result of that was a predictable surge in cash from operations.

CSX Operating Margin (TTM) Chart
CSX Operating Margin (TTM) data by YCharts.

In addition to the margin improvement, CSX also improved its safety, terminal dwell time, all while increasing its on-time arrivals over the past decade. Compared to trucking, shipping by rail is cheaper over long distances and is roughly four times more fuel efficient per ton-mileĀ -- an advantage that will become even more important if and when gas prices rise again.

Look, it's been a rough go for railroads and, to be honest, that isn't going to change this year. That doesn't mean railroads like CSX don't offer great opportunities over the long term, and keep in mind that the company's cost-cutting business improvements have delivered earnings-per-share growth despite a $1.4 billion decline in coal revenue since 2011. While investors wait for CSX's stock price to move higher, its dividend totals $0.72 per share annually for a current 2.8% yield, and with such drastic improvements in its margins and cash flow from operations, it should be a safe bet going forward.