In Chapter Twelve of Half-Blood Prince Harry discovers the Levicorpus spell in the prince’s potions book:
Sitting up in bed, Harry turned the book sideways so as to examine more closely the scribbled instructions for a spell that seemed to have caused the Prince some trouble. There were many crossings-out and alterations, but finally, crammed into a corner of the page, the scribble:
Levicorpus (nvbl)
This book is the sixth year potions textbook, which would imply that Snape (the prince) invented the spell in his sixth year at Hogwarts.
However, in Chapter Twenty-Eight of Order of the Phoenix Harry sees Snape’s memory in which James used the spell on Snape:
But too late; Snape had directed his wand straight at James; there was a flash of light and a gash appeared on the side of James’s face, spattering his robes with blood. James whirled about; a second flash of light later, Snape was hanging upside down in the air, his robes falling over his head to reveal skinny, pallid legs and a pair of graying underpants.
In Chapter Sixteen of Half-Blood Prince Harry discusses this with Lupin, who confirms that the spell was already popular by then and might have been around even earlier:
“It’s nothing to do with me!” said Harry indignantly. “The Half-Blood Prince is someone who used to go to Hogwarts, I’ve got his old Potions book. He wrote spells all over it, spells he invented. One of them was Levicorpus —”
“Oh, that one had a great vogue during my time at Hogwarts,” said Lupin reminiscently. “There were a few months in my fifth year when you couldn’t move for being hoisted into the air by your ankle.”
“My dad used it,” said Harry. “I saw him in the Pensieve, he used it on Snape.”
He tried to sound casual, as though this was a throwaway comment of no real importance, but he was not sure he had achieved the right effect; Lupin’s smile was a little too understanding.
“Yes,” he said, “but he wasn’t the only one. As I say, it was very popular….You know how these spells come and go….”
“But it sounds like it was invented while you were at school,” Harry persisted.
“Not necessarily,” said Lupin. “Jinxes go in and out of fashion like everything else.”
Given that Snape’s memory was from his fifth year, and the spell had already spread throughout the school by that point, the spell must have been invented prior to Snape’s sixth year. Why, then, would the spell be in his sixth year textbook?
He wrote spells all over it, spells he invented. One of them was Levicorpus —”
Harry is assuming the HBP invented the spell, where it could have been HBP discovering it.