27 ms·
If GCC has a correctly defined DAG of asm() statements, it might not be able to apply things like De Morgan's Law, but it can do a lot. Usually what gets optim
by jart 7y ago
If GCC has a correctly defined DAG of asm() statements, it might not be able to apply things like De Morgan's Law, but it can do a lot.
Usually what gets optimized the most, counter-intuitively, is the adjacent code that the compiler generates itself, rather than the handwritten assembly you supply (which can in fact be empty string). This basically gives you a means of controlling the compiler's internal algorithms for performing register allocation.
Take for example foo(). If that were written as asm() it'd imply asm("call foo" ::: rax, rcx, rdx, r8, r9, r10, r11, r12, xmm0, xmm1, etc.). If you know ahead of time that foo won't clobber those million different things, then explicitly using asm() can have a wild impact. I've seen just one of those alone cut down the code size of large functions by a third.