public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/97961] New: unnecessary moves with __builtin_{add,sub}_overflow_p and __int128
@ 2020-11-23 17:58 denis.campredon at gmail dot com
  2022-11-08  0:14 ` [Bug rtl-optimization/97961] " pinskia at gcc dot gnu.org
  2023-01-19 23:23 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: denis.campredon at gmail dot com @ 2020-11-23 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97961
           Summary: unnecessary moves with __builtin_{add,sub}_overflow_p
                    and __int128
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

In #97950 Jackub told me to open a new bug for that.

The snippet bellow has the following problems
- f1 and f2 generate 4 unnecessary moves
        mov     r9, rdi
        mov     r8, rsi
        mov     rsi, r9
        mov     rdi, r8

- f4 has "only" 2 unnecessary moves
        mov     r9, rdi
        mov     rdi, rsi

- f3 should be identical to f4 except for the flag checking.


------------
bool f1(unsigned __int128 a,unsigned __int128 b) {
    return __builtin_add_overflow_p(a, b, (unsigned __int128)0);
}

bool f2(__int128 a,__int128 b) {
    return __builtin_add_overflow_p(a, b, (__int128)0);
}


bool f3(unsigned __int128 a,unsigned __int128 b) {
    return __builtin_sub_overflow_p(a, b, (unsigned __int128)0);
}

bool f4(__int128 a,__int128 b) {
    return __builtin_sub_overflow_p(a, b, (__int128)0);
}
------------

asm generated
------------
f1(unsigned __int128, unsigned __int128):
        mov     r9, rdi
        mov     r8, rsi
        mov     rsi, r9
        mov     rdi, r8
        add     rsi, rdx
        adc     rdi, rcx
        setc    al
        ret
f2(__int128, __int128):
        mov     r9, rdi
        mov     r8, rsi
        mov     rsi, r9
        mov     rdi, r8
        add     rsi, rdx
        adc     rdi, rcx
        seto    al
        ret
f3(unsigned __int128, unsigned __int128):
        mov     r9, rdi
        mov     r8, rsi
        mov     rdi, r8
        mov     rax, r9
        mov     r8, rdx
        sub     rax, r8
        mov     rdx, rdi
        sbb     rdx, rcx
        cmp     r9, rax
        mov     rcx, rdi
        sbb     rcx, rdx
        setc    al
        ret
f4(__int128, __int128):
        mov     r9, rdi
        mov     rdi, rsi
        cmp     r9, rdx
        sbb     rdi, rcx
        seto    al
        ret
-------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/97961] unnecessary moves with __builtin_{add,sub}_overflow_p and __int128
  2020-11-23 17:58 [Bug tree-optimization/97961] New: unnecessary moves with __builtin_{add,sub}_overflow_p and __int128 denis.campredon at gmail dot com
@ 2022-11-08  0:14 ` pinskia at gcc dot gnu.org
  2023-01-19 23:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-08  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-11-08

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
aarch64 produces the code without any extra moves ...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/97961] unnecessary moves with __builtin_{add,sub}_overflow_p and __int128
  2020-11-23 17:58 [Bug tree-optimization/97961] New: unnecessary moves with __builtin_{add,sub}_overflow_p and __int128 denis.campredon at gmail dot com
  2022-11-08  0:14 ` [Bug rtl-optimization/97961] " pinskia at gcc dot gnu.org
@ 2023-01-19 23:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-19 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 94804. The problem is arguments.
If we do:
```
bool f1(unsigned __int128 *a,unsigned __int128 *b) {
    return __builtin_add_overflow_p(*a, *b, (unsigned __int128)0);
}

bool f2(__int128 *a,__int128 *b) {
    return __builtin_add_overflow_p(*a, *b, (__int128)0);
}


bool f3(unsigned __int128 *a,unsigned __int128 *b) {
    return __builtin_sub_overflow_p(*a, *b, (unsigned __int128)0);
}

bool f4(__int128 *a,__int128 *b) {
    return __builtin_sub_overflow_p(*a, *b, (__int128)0);
}
```
We don't get extra mov's.

*** This bug has been marked as a duplicate of bug 94804 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-19 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 17:58 [Bug tree-optimization/97961] New: unnecessary moves with __builtin_{add,sub}_overflow_p and __int128 denis.campredon at gmail dot com
2022-11-08  0:14 ` [Bug rtl-optimization/97961] " pinskia at gcc dot gnu.org
2023-01-19 23:23 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).