I believe that it does matter. Just like with humans, what you eat can affect your health. You have to think back 30 years or so when there was very little choice on the market. If your dog lived to be 8 years old, that was considered a good long life. Today 12 to 14 years old isn't that far fetched for a large dog (smaller breeds can live even longer).
You can attribute some of it to improved medical care. But, I believe improved dog food has made a big difference. If not for the longevity, then for the quality of life.
Case in point, my sister's dog has epileptic seizures. She is on medication. About 3 years ago, they switched her dog food. Then, 2-3 months later the dog began having cluster seizures after not having any for a year or more. The doctor tried moderating her medication, but it didn't help. They focused on the dog food and found that one nutrient (I'm guessing, but I think it was protein) was too high for a dog with seizures. When they switched her to a food that had a lower amount, the seizures went away.
Also, my brother's dogs who were on one of the Purina varieties. They all broke out with horrible bumps. It took awhile to realize it wasn't something in the environment, but it was the dog food. They switched to a better brand and the problem went away.
I always remember when my first dog was on Science Diet. It made her produce so much stool. I talked to the vet about it and she thought it was way too many times a day. I switched her to a Nature's Recipe variety and she had more normal stool production.
I know that cost is an issue for many. I think it can be worth it to do the research and try to get the best quality dog food that you can afford. It may save you hassles and medical bill costs.