5 ms·
> Of course instruction parallelism should be in the hands of the compiler -- it has so much richer information from the source-code so it can do a better job.
by frankpf 9y ago
> Of course instruction parallelism should be in the hands of the compiler -- it has so much richer information from the source-code so it can do a better job.
This is not true. Yes, the compiler has a lot of useful information, but it does not have access to runtime information, which the CPU does.
A modern superscalar CPU with out-of-order execution can execute instructions speculatively hundreds of cycles before they are even used.
Instructions after conditional branches can be executed speculatively using branch prediction and loads can be executed before stores (even though they might access the same address!). If the processor later detects that the load was dependent on the store, it can "undo" that operation, without any of these effects ever being visible to the running program.
- Laaas 9y agoWhile you are right, the compiler should still definitely do most of the job. There's simply no reason to keep track of dependencies, etc. at run-time, instead of doing this compile-time.
- striking 9y agoSome of that information doesn't exist at compile time...
- jonhohle 9y agoDo you have any examples of when this beats a C program compiles with `-march -O2`? I've read about this promise of JIT optimization being able to generate optimal code on hot paths, but in practice I've never seen it work out that way. Good AOT compilers exist today and consistently generate optimized machine code.
- ksk 9y agoYour C code is already executed by the CPU in a JIT optimized way because of the way the x86 architecture is implemented on the CPU. What more proof do you want?! :)
- Laaas 9y agoI don't exactly know what you're searching for, but I've heard of LuaJIT beating GCC, etc. in some rare cases.
- jonhohle 9y agoI'm honestly searching for examples of a JIT beating an AOT because it had runtime information the AOT couldn't know.
- Laaas 9y agoHow so? When the compiler generates code like add eax, eax add ebx, ebx Of course it knows that they are independent. They could then be represented in the ISA as a block of sorts.