[Bug target/82858] __builtin_add_overflow() generates suboptimal code with unsigned types on x86

2017-11-06 Thread ubizjak at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82858

--- Comment #5 from Uroš Bizjak  ---
Actually, -m32 -march=i386 -mtune=generic generates expected code:

movl8(%esp), %eax
addl4(%esp), %eax
sbbl%edx, %edx
orl %edx, %eax
ret

-march=i386 does not have cmove.

[Bug target/82858] __builtin_add_overflow() generates suboptimal code with unsigned types on x86

2017-11-06 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82858

--- Comment #4 from Marc Glisse  ---
unsigned c;
unsigned d = __builtin_add_overflow(a, b, )?-1:0;
return c|d;

gives the expected asm. Ideally phiopt would recognize a saturing add pattern,
but we have nothing to model it in gimple. We could turn it into the branchless
BIT_IOR form though.

(the problem isn't with __builtin_add_overflow but with what comes afterwards)

[Bug target/82858] __builtin_add_overflow() generates suboptimal code with unsigned types on x86

2017-11-06 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82858

--- Comment #3 from Markus Trippelsdorf  ---
(In reply to Liu Hao from comment #2)
> Trunk on  produces the following code:
> 
> ```
> saturated_add(unsigned int, unsigned int):
>   add edi, esi
>   mov eax, -1
>   cmovnc eax, edi
>   ret
> ```
> 
> Condition moves are however, in my opinion, nothing better than branches, or
> they could be something worse: 

Linus is talking about the Pentium 4. Hardware has evolved since then.
On today's CPUs CMOV is fine.

[Bug target/82858] __builtin_add_overflow() generates suboptimal code with unsigned types on x86

2017-11-06 Thread lh_mouse at 126 dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82858

--- Comment #2 from Liu Hao  ---
Trunk on  produces the following code:

```
saturated_add(unsigned int, unsigned int):
  add edi, esi
  mov eax, -1
  cmovnc eax, edi
  ret
```

Condition moves are however, in my opinion, nothing better than branches, or
they could be something worse: 

[Bug target/82858] __builtin_add_overflow() generates suboptimal code with unsigned types on x86

2017-11-06 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82858

Markus Trippelsdorf  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-11-06
 CC||trippels at gcc dot gnu.org
  Known to work||8.0
 Ever confirmed|0   |1
  Known to fail||6.4.1, 7.2.1

--- Comment #1 from Markus Trippelsdorf  ---
Confirmed. Trunk is fine.