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

            Bug ID: 105295
           Summary: missed optimization with -ftrapv for conditional
                    constants
           Product: gcc
           Version: 12.0
               URL: https://godbolt.org/z/4rojo77a7
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland.illig at gmx dot de
  Target Milestone: ---

~~~c
int sum_const(_Bool a, _Bool b)
{
        return (a ? 1 : 0 ) + (b ? 1 : 0);
}

int sum_unknown(int a, int b)
{
        return a + b;
}
~~~

For both functions, GCC calls __addvsi3, even though in sum_const, it is easy
to see that no overflow can ever happen since the sum is always in the range [0
... 2].

Clang optimizes this code reasonably.

ICC apparently does not care about -ftrapv at all.

Reply via email to