As I understand it, currently there is no equivalent in GDC of GCC's asm volatile (to prevent optimisation-to-nothing, or motion). Is this correct?
If you wish to prevent certain nasties, such as either optimisation away to nothing, or code motion, in certain situations when using calls to GDC extended asm blocks, then what are the possibilities for a workaround? (I've read about tricks such as introducing a fake output from an asm block plus a dependency on an ‘anchor’ in the rest of the code, which might or might not work.) Such things seem flaky and are rather unattractive if the code needs to be ultra-high-performance, but maybe that's just life.
I suppose there is a general question: never mind asm, how do you prevent compilers from just deleting code altogether if it is actually needed because of its side-effects, eg i/o? Is it a really stupid question to ask why a compiler doesn't just delete calls to eg printf(), it would certainly speed the code up, and the rest of the code doesn't depend on it. Is it all down to where inlining, whole-program optimisation / LTO fails and beyond that a compiler has to be conservative and assume that calls to functions that have no outputs actually do something useful?