For a while I've been thinking of creating an optimizer tool for assembler code. As a starting point, I was just thinking of simple optimizations (like automatic replacement of "cp 0" by "or a", etc. but doing them ensuring that the optimizations maintain functionality with 100% guarantees, so, the optimizer would have to make sure the replacements do not alter any flags that are later used, etc.). There are lots of Z80 assembler pages with optimization tricks (e.g.: http://z80-heaven.wikidot.com/optimization https://wikiti.brandonw.net/index.php?title=Z80_Optimization , but there are many others).
Of course, it'd be great to have more advanced optimization by turning the code into some sort of abstract representation and then optimizing that. But that seems like a much larger undertaking, that might take much more work.
I was also thinking of "optimizing for speed" vs "optimizing for space" options.
So, anyway, my question is if you are aware of any such tool already existing, or if any one has anything started on that direction. I spend hours upon hours optimizing code for making my games run as smooth as possible, and often I think if it would be more worth it to try to put my effort into creating an optimizer that does automatically everything I do manually, and maybe more.