https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83133
--- Comment #2 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> --- (In reply to Uroš Bizjak from comment #1) > (In reply to Maxim Egorushkin from comment #0) > > g function assembly contains a superflous test instruction. It should not > > generate that instruction, since sub instruction already sets all the > > required flags. I first discovered this issue in gcc-4.9.2 and it is still > > there in gcc-7.2.0. > > SUBL also sets overflow flat (OF). JLE in fact jumps when (ZF=1 or SF≠OF), > so assuming OF is always cleared is waaay to dangerous. > > As a matter of fact, flag-setting cmp/sub/add patterns can be changed to > operate in CCNOmode instead of CCGOCmode when strict signed overflow rules > are in effect (in C/C++ signed overflow is undefined, so we CAN assume > signed overflow never happens and consequently flag OF is never set), but it > would be major PITA on x86 architecture, where plus and minus operations on > signed integers always overflow "as expected". > > (BTW: I did implement the above idea, but compiler failed bootstrap > comparison check. I'm surprised clang was brave enough to implement this > dangerous optimization.) Could you provide an example where that "dangerous optimization" would break well-formed code please?