How long have you been riding? Honestly for 40 miler you don't really need any special food, unless it's very high intensity or something. If you are getting tired 20 miles in to it I would look in to the routine off the bike. Are you getting enough sleep, are you eating enough off the bike, what kind of food you are eating, etc.