My hunch is that due to the halting problem, incompleteness, and Entscheidungsproblem, it would be extremely difficult, if not impossible, to do such high level optimization. But I would like to hear what HN has to say. Thanks!
[1] https://en.wikipedia.org/wiki/Selection_algorithm
[2] https://en.wikipedia.org/wiki/Entscheidungsproblem