Today while programming I stumbled upon the following question - are there any compilers which optimize based on mathematical assumptions?
For instance in cases like
unsigned int i,b; (i,b not constant) if(sqrt(i) == b) ...
In this case it would be a lot more effective to use
unsigned int i,b; (i,b not constant) if(i == b*b) ...
Assuming a sqrt() function, that handles unsigned integers and rounds sensefully.
Since I was not able to find useful information (probably because I did not know what to search for specifically), can someone please tell me or point me to a relevant source?
Are there compilers (for imperative languages) who optimize such things using some kind of heuristic? Or more specifically - what about gcc and microsoft visual c++ and matlab?