The revelation comes ahead of the anniversary of the birth of her baby boy, who she delivered stillborn six months into her pregnancy after contracting a viral infection.
In a series of tweets, the singer shared a link to the song with her 5.4 million followers and asked them to donate to Sands, the stillbirth and neonatal death charity, in memory of her late son.
The song, written for the Peter Pan spin-off featuring Hugh Jackman, is called Something's Not Right. In the emotional track, Lily sings: 'Something's not right, 'cause I know that it's day but it's dark outside, and I feel a weight in my heart tonight. We had forever, we never got it together. They kept telling me that it was unlikely, all I had to do was keep you beside me.'
5 years ago today I was admitted to hospital. 4 days later I delivered a beautiful baby boy, but sadly he didn't make it.— lily (@lilyallen) October 27, 2015
It's unlike me to discuss this sort of thing so publicly but I wrote this song in his memory when writing something for @panmovie— lily (@lilyallen) October 27, 2015
The 30 year old married her partner Sam Cooper in June 2011, and it was later confirmed that at the time of the ceremony she was already pregnant again with daughter Ethel, now three years old. The couple also have another daughter, two year old Marnie.
This is not the first time the artist has spoken about the loss of her first child. In 2014, Lily said: 'It was horrendous and something I would not wish on my worst enemy. It's something that I still haven't dealt with. I never will get over it. I held my child and it was really horrific and painful - one of the hardest things that can happen to a person.'
The author of hit Smile, who had previously suffered a miscarriage in 2008 when four months pregnant, also said she nearly died because of septicaemia, but she didn't care: 'I'd just lost my baby and that is a reflection of how numb I was.'
Five years on, the couple make sure their first child is never forgotten. 'We've got a little stone in our garden with his name on. And lots of different things that I do, rituals, I have him in my mind.'
Find out more about Sands and how you can donate here.