I remember a paper on "Superoptimization" back in the 80's. It worked by starting with an algorithm, and doing an exhaustive search of every instruction sequence to see if the sequence implemented the algorithm. Of course, it only worked for very small algorithms, but it produced some very interesting results that were promptly incorporated into about every compiler.