It does two passes of the program text. And then does three dozen passes after that. Each pass does what you suggest, only one thing.
https://blogs.msdn.microsoft.com/ericlippert/2010/02/04/how-...
I think it's still fast because the passes are all or mostly O(n).
On a more local basis, if you program in a language that encourages it, composing work at compile time can save a huge amount of cruft that one might imagine comes with using a many-pass compiler.
https://d.godbolt.org/z/w9At24 (Already posted on this thread), I wrote this little example to show how you can compose series of discrete manipulations in D into what is indistinguishable from a normal function as if it were monolithically written by hand.
That example (in D, in particular) could be made as pure-functional and discrete as is desired but I used pointers to keep it small.
Compilers are extremely good at optimizing interprocedural code, or at least better than a human, so a certain level of lazyness can be bestowed upon the programmer at the expense of trusting a compiler.
That's called optimization, baby!
It greatly reduces the surface area that needs to be tested while also keeping the compiler's code from being spaghetti crap which can often happen in non-toy compilers.