I had been getting the P0171 code sporadically over the last couple years. In the last few months it was more common but still not consistent. The MAF sensor had been replaced. I was also having problems starting every once in a while and finally after getting the car started and running weak it stalled, also got a misfire code. I noticed that I did not hear the fuel pump when I turned the ignition on so I banged on the tank and it kicked on?!? So after getting a premium pump on ebay $45 shipped I have not had the code since. One thing I would recommend is to get the fuel pump o-ring before you start. The old one will not be reusable as is swells after being installed. I could only find at a GM dealer for $7. I would have thought it would be with the pump but was not.
Also since getting the new pump gas mileage has improved by 5mpg. I have also realized that i do not hear the fuel pump as much as the old , I guess that might be an indication it is going bad.