https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30484
--- Comment #18 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Vincent Lefèvre from comment #16)
> int f (int a, int b, int c)
> {
> if (b < 0)
> return a + b + c;
> else
> return a + c + b;
> }
>
> The generated code with -O3 has 6 instructions:
>
> leal (%rdi,%rdx), %eax
> addl %esi, %edi
> addl %edx, %edi
> addl %esi, %eax
> testl %esi, %esi
> cmovs %edi, %eax
>
> In theory, the compiler could normally optimize to produce the same code as
> with the source that assumes -fwrapv (here, a + b + c and a + c + b are
> obviously equivalent on a typical processor), but in practice, this is often
> not the case as shown above.
Surprisingly, GCC can optimize this second test to 2 instructions with -fwrapv.
I've reported PR102032 about the missed optimization without -fwrapv.