If there were an algorithm that could optimize algorithms, we programmers would all be out of a job. However, we already perform small optimizations in compilers. Small optimizations can be made which do not change the intended meaning of the operation, however our limitation is precisely that: intended meaning. For instance, if we knew that a number is always positive, we could replace multiplication by 2 with bit shifting. However, when we are left with signed integers, even if they are used purely for positive numbers, the compiler cannot make these sorts of assumptions.
The real trick is understanding what the algorithm is supposed to do. If you understand that, then you realize that an algorithm is not about the steps it takes but about the end result. Without this, there is very little hope to improve on an algorithm. For example, if you give your friend instructions for getting to your house and you don't see the bigger picture, you may never realize that you made your friend take a longer route to get there.
So how do you define the context of an algorithm? It boils down to input and output. If you can make mathematical assumptions on the input and describe the expected assumptions on the output, then an algorithm is simply a mathematical proof in its purest form, describing all the steps you'd need to perform in order to guarantee that for the given input, you receive the expected output.
Each step is transformed into an equivalent mathematical transformation (for instance, performing a loop which accumulates values could be thought of as a sum operation). Once you have this, you can not only begin to prove soundness and correctness but you can also simplify much like you would combine like terms in a mathematical formula.
Of course this is all very theoretical and ongoing, but the idea is that we can one day write compilers which can not only tell you that your algorithm won't work as expected, but also on what line and how to fix it as well as any optimizations which can be made to improve performance (this would likely be done upon automatically).
Unfortunately we are not yet at this stage, but I hope to see it sometime in my lifetime anyway. I hope that answers your question.