Gilead Sciences (GILD -1.20%) has a bright future ahead with HIV treatment Sunlenca obtaining approval from the Food and Drug Administration last year and cancer drug Trodelvy continuing to show strong growth. However, despite its strong growth prospects today, Gilead Sciences hasn't always made for a good investment. Last year, the stock did something it hadn't done in the previous six years.

In 2022, Gilead Sciences stock outperformed the S&P 500

In recent years you would have been better off investing in the S&P 500 most of the time because the index has fairly consistently outperformed the healthcare stock. Last year, however, was an exception, with Gilead's returns finally eclipsing the broad market index:

Source: Ycharts.

Why has Gilead Sciences stock struggled?

The simple reason for Gilead's woes is that the business has had trouble generating growth. The company's top line has fallen over the years as losses in exclusivity and rising competition have led to less revenue for the business. Last year, Gilead's top line was little changed because lower revenue from COVID-19 treatment Veklury offset growth in its oncology and HIV segments.

GILD Revenue (Annual) Chart

Data source: YCharts GILD Annual Revenue

The company hasn't offered much for investors besides its dividend. But when a business isn't growing and its financials have been worsening, that creates doubts about the payout, which can lead to investors preemptively dumping the stock.

The future is much brighter for Gilead Sciences

It's temping to look at Gilead Sciences' performance over the past several years and assume the stock's future returns will be equally unimpressive. But that might be a mistake.

Its latest earnings results came out last month, and for the first quarter of 2023, Gilead's product sales rose by 15% when excluding Veklury. Its core HIV business, which accounts for the bulk of the company's revenue, came in at just under $4.2 billion and increased by 13% year over year. Its oncology segment, which presents a great growth opportunity for Gilead, brought in $670 million in sales, soaring by 59% from the prior-year period.

The company is on a much better path right now, with Sunlenca potentially being a game changer for HIV patients because it only requires an injection twice a year (HIV pills typically need to be taken daily). It could generate as much as $1.5 billion in revenue for Gilead. And Trodelvy is another blockbuster in the making. The cancer drug is approved for three indications (related to breast and bladder cancer) and analysts estimate it could generate $2 billion in revenue by 2026.

Should you buy Gilead Sciences stock?

Gilead Sciences stock trades at a multiple of 12 times its future estimated earnings. That's a modest valuation compared to the average healthcare stock, which carry a multiple of 18. There's good value here for investors because Gilead has strong growth prospects and analysts in recent months have set price targets of $100 or more for the stock, up from a recent price of about $80.

Plus, Gilead also pays an attractive dividend yield of 3.7%. And over the past five years, it has raised its payout by 32%.

Investors shouldn't let a bad past performance dissuade them from buying shares of Gilead Sciences. This is a much stronger business now than it was just a few years ago. Buying the stock today could be a good move for long-term investors.