Branchless code sequences
davespace.co.uk
davespace.co.uk
Jha, Gulwani and colleagues have a very nice paper on oracle-guided synthesis. They show how you can generate loop-free bitvector programs using SMT: http://www.eecs.berkeley.edu/~sseshia/pubdir/synth-icse10.pd.... John Regehr has also written about this on his blog: http://blog.regehr.org/archives/1146.
Part of the complexity here in an SMT solution might be encoding all the bizarre instructions that you could possibly take advantage of in x86-like instruction sets.
http://theory.stanford.edu/~aiken/publications/papers/asplos...
They managed to beat gcc -O3 - "we show speedups from 1.7 to a factor of 10 on some compute intensive kernels"
I ran into it a couple years ago, after hearing from other research from her. Her papers are really impressive. I would have loved that the author of the article had mentioned her.
On a side note, I wouldn't be surprised if the JIT compilers were doing some use of this, allowing some interpreted language to have better performances than compiled C on some benchmarks
EDIT : formatting and JIT addition
You'd probably freak out and worry about getting ATM card back.
They tend to be good at finding obscure solutions.
First, it does an exhaustive search on all possible instruction combinations.
Second, it does not _prove_ that the resulting instructions do the same as the original code. It shows it only for some random numbers and border cases.
Though that's probably too much machinery to add on to a compiler.
Especially since these kinds of transformations could slow down your code if the branch predictor is working well for your code set.
A bit of code that eliminates branches but has dependant variables (A must be computed before B can be computed) will have pipeline stalls while the computation for A is completed. Yes it might be faster than a branch misprediction but it will never be as fast as a correctly predicted branch (which takes effectively 0 cycles).
Notice the one thing missing in this post? Benchmarks!