Integer Overflow/Wrap and GCC Optimizations
Marc Glisse
marc.glisse@inria.fr
Thu Jan 24 15:13:00 GMT 2013
[ gcc-help@gcc.gnu.org ? ]
On Thu, 24 Jan 2013, Jeffrey Walton wrote:
> Hi All,
>
> I have a question on integer overflow and wrap, and GCC optimizations.
>
> I have a small library that uses inline assembly to check OV/CY flags
> for both x86/x64 and ARM. x86/x64 uses FLAGS/EFLAGS, while ARM uses
> CPSR.
>
> Do I have to worry about GCC optimizing out addition, subtractions,
> etc under any circumstances?
It would help to see what kind of code you are worried about. If the
addition is done in an inline asm, gcc doesn't know it is an addition and
doesn't optimize it. If it is done outside the asm, you don't have any
guarantee that once the asm starts the flags are still what you want.
Note that using unsigned types would avoid a lot of issues.
--
Marc Glisse
More information about the Gcc
mailing list