3 ms·
Even if you could write perfect assembly, sticking it in your program makes it more difficult for optimizations to flow across the assembly you have written bec
by cokernel_hacker 12y ago
Even if you could write perfect assembly, sticking it in your program makes it more difficult for optimizations to flow across the assembly you have written because it is opaque to the compiler.
Better yet, imagine that the compiler has performed value range propagation [1] to determine that the range checks, after inlining, were redundant or simply elidable. This would be infeasible if it were written in assembly.
[1] http://llvm.org/devmtg/2007-05/05-Lewycky-Predsimplify.pdf http://llvm.org/devmtg/2007-05/05-Lewycky-Predsimplify.pdf
- userbinator 12y agoIf compilers don't understand inline Asm, maybe instead of avoiding it, why not try improving the compiler so it can understand? I know this can't be done if e.g. you use newer instructions that it doesn't know about and wouldn't emit anyway, but in the case of faster, shorter sequences using existing instructions and having an equivalent in C, I don't see why it can't "decompile" the instructions you write and use that information for optimisation. Even better if the compiler can learn from it and use that faster/shorter instruction sequence when it sees that expression in the future. Better yet, imagine that the compiler has performed value range propagation [...] This would be infeasible if it were written in assembly. VRP doesn't depend on the instruction set; it could be LLVM IR or it could be x86 or ARM or 6502 or anything else. It's just looking at values and operations on them.
- ksk 12y agoHuh? ... decompile the optimized instructions to what? There is no "equivalent C". That's the entire point. Otherwise someone would just write it in C and the codegen would emit the optimized instructions.
- erichocean 12y ago> Huh? ... decompile the optimized instructions to what? To the compiler's own IR, whatever that is.
- caf 12y agoYes - the original article mentions this at the end of the first paragraph.