[Bug tree-optimization/92229] New: Optimization makes it impossible to read overflow flag

arieltorti14 at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 25 16:54:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92229

            Bug ID: 92229
           Summary: Optimization makes it impossible to read overflow flag
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arieltorti14 at gmail dot com
  Target Milestone: ---

I'm implementing a builtin to read the overflow flag. It is meant to be used to
simply the overflow checking code, instead of doing:

ov = __builtin_smul_overflow(a, b, &res);
if (ov) { ... }

One could make the code more readable by using:

res = a * b;
if (__builtin_overflow_p()) { ... }

The problem GCC optimizes many multiplication and addition operations by using
`lea` which doesn't set the overflow flag, which makes it impossible to do the
check.

What approach could I take to implement this ? Do note that this builtin is
only available on x86.


More information about the Gcc-bugs mailing list