[Bug target/83133] Superflous x86 test instructions in generated assembly.

maxim.yegorushkin at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Nov 24 17:20:00 GMT 2017


--- Comment #10 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> ---
(In reply to Uroš Bizjak from comment #8)
> (In reply to joseph@codesourcery.com from comment #5)
> > Both 32-bit and 64-bit ABIs make the values of flags in EFLAGS (other than 
> > DF) undefined on function entry and return.  Thus, a function can never 
> > assume anything about the value of OF unless it has executed an 
> > instruction known to set/clear it and has not called any other functions 
> > since then.
> In the testcase, there is nothing that violates ABI.

Not sure why ABI got involved here.

> It all happens in "g"
> that passes calculated result to a function. Selected function depends on
> flags, calculated from the subtraction, and wrong function gets selected
> when overflow happens.

The underflow happens as a result of that subtraction. That underflow leads to
UB. In the case of UB, both gcc and clang behaviours are valid. The clang
behaviour is one instruction cheaper though.

More information about the Gcc-bugs mailing list