I was on a team of three building a compiler for a microprocessor. I was writing the code generator which included register allocation and other hairy stuff. We had to produce pretty good code, as assembler was being replaced by our compiled code. Well, register allocation can be pretty hairy, and we were under a deadline. I had stayed up very late working on the problem, but didn't really finish when I crashed. I was half dreaming nonsense most of the night, but had one flash of inspiration in the middle of the night that solved the core of the problem.
It was not exactly restful sleep. Not sure it was really sleep, I would say.