3 ms·
As an example optimization, consider this C code: do { if (*--p == '.') *p = '_'; } while (p != name); LLVM originally produced this bitcode for AVX-2
by chrisaycock 3y ago
As an example optimization, consider this C code:
do {
if (*--p == '.') *p = '_';
} while (p != name);
LLVM originally produced this bitcode for AVX-2 instructions:
%1 = shufflevector %0, <31, 30, 29, ... , 0>
%2 = icmp eq %1, <46, 46, 46, ... , 46>
%3 = shufflevector %2, <31, 30, 29, ... , 0>
Minotaur instead produced:
%1 = icmp eq %0, <46, 46, 46, ... , 46>
Both compare the register to ASCII 46 ('.'), but LLVM originally produced an unnecessary pair of vector reversals. Minotaur removed it.
- addaon 3y agoSuper-optimizers always strike me with the same feeling when seeing examples like this. On the one hand, it's awesome to be able to have truly-optimal (under chosen assumptions) code sequences for certain operations. On the other hand, so many of the examples just hammer home how many missed practical opportunities there are for peephole optimizations (in this case) and other traditional, local optimization techniques. I almost feel like the most valuable use of a super-optimizer would be to run it against a bunch of real world code patterns, and then use the optimization results to feed back in to simple traditional optimizations.
- xxpor 3y agoThat is in fact what they're usually used for.
- eslaught 3y agoYou're exactly right: https://theory.stanford.edu/~aiken/publications/papers/asplos06.pdf https://theory.stanford.edu/~aiken/publications/papers/asplo...
- viraptor 3y agohttps://github.com/google/souper https://github.com/google/souper > Souper is a superoptimizer for LLVM IR. It uses an SMT solver to help identify missing peephole optimizations in LLVM's midend optimizers.
- thechao 3y agoThe posted paper is by John, as well as Souper!
- mhh__ 3y agoLLVM generates so much more code than GCC for that. Crazy - obviously the compiler is damned if it does, damned if it doesn't, but optimizing for small strings is probably not a bad idea.
- bjourne 3y agoIsn't this "just" a bug in LLVM? If you make the code run forwards instead of backwards it will not insert the redundant shuffles.