It's from a Star Fox game... doing a barrel roll would make you temporarily invulnerable, so one of the non-player characters in the game would tell you to do a barrel roll any time you got in trouble... so pretty much constantly.
It came to be later used as the joke solution to any problem.
And thanks!