public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/104582] New: Unoptimal code for __negdi2 (and others) from libgcc2
@ 2022-02-17 12:30 ubizjak at gmail dot com
  2022-02-17 12:35 ` [Bug tree-optimization/104582] " ubizjak at gmail dot com
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: ubizjak at gmail dot com @ 2022-02-17 12:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104582
           Summary: Unoptimal code for __negdi2 (and others) from libgcc2
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Following testcase (taken from libgcc):

--cut here--
typedef          int DItype     __attribute__ ((mode (DI)));
typedef unsigned int UDItype    __attribute__ ((mode (DI)));
typedef          int TItype     __attribute__ ((mode (TI)));

#define Wtype   DItype
#define UWtype  UDItype
#define DWtype  TItype

#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
  struct DWstruct {Wtype high, low;};
#else
  struct DWstruct {Wtype low, high;};
#endif

typedef union
{
  struct DWstruct s;
  DWtype ll;
} DWunion;

DWtype
__negdi2 (DWtype u)
{
  const DWunion uu = {.ll = u};
  const DWunion w = { {.low = -uu.s.low,
                       .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };

  return w.ll;
}
--cut here--

compiles with -O2 on x86_64 to:

__negdi2:
        movq    %rdi, %rax
        negq    %rsi
        negq    %rax
        cmpq    $1, %rdi
        adcq    $-1, %rsi
        movq    %rax, %xmm0
        movq    %rsi, %xmm1
        punpcklqdq      %xmm1, %xmm0
        movaps  %xmm0, -24(%rsp)
        movq    -24(%rsp), %rax
        movq    -16(%rsp), %rdx
        ret

Please note the convoluted sequence to move the value at the end.

gcc-10 compiles the code to:

__negdi2:
        negq    %rsi
        movq    %rdi, %rax
        negq    %rax
        movq    %rsi, %rdx
        cmpq    $1, %rdi
        adcq    $-1, %rdx
        ret

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

end of thread, other threads:[~2023-05-29 10:06 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17 12:30 [Bug target/104582] New: Unoptimal code for __negdi2 (and others) from libgcc2 ubizjak at gmail dot com
2022-02-17 12:35 ` [Bug tree-optimization/104582] " ubizjak at gmail dot com
2022-02-17 12:45 ` ubizjak at gmail dot com
2022-02-17 15:28 ` [Bug tree-optimization/104582] [11/12 Regression] Unoptimal code for __negdi2 (and others) from libgcc2 due to unwanted vectorization jakub at gcc dot gnu.org
2022-02-17 16:35 ` jakub at gcc dot gnu.org
2022-02-17 16:40 ` jakub at gcc dot gnu.org
2022-02-18  0:43 ` pinskia at gcc dot gnu.org
2022-02-18  7:26 ` rguenth at gcc dot gnu.org
2022-02-18  8:37 ` jakub at gcc dot gnu.org
2022-02-18  8:48 ` rguenth at gcc dot gnu.org
2022-02-18  8:53 ` rguenth at gcc dot gnu.org
2022-02-18  9:02 ` jakub at gcc dot gnu.org
2022-02-18  9:28 ` rguenther at suse dot de
2022-02-18 10:19 ` rguenth at gcc dot gnu.org
2022-02-18 10:22 ` rguenth at gcc dot gnu.org
2022-02-18 10:50 ` rguenth at gcc dot gnu.org
2022-02-18 11:31 ` rguenth at gcc dot gnu.org
2022-02-18 13:37 ` rguenth at gcc dot gnu.org
2022-02-18 13:45 ` rguenth at gcc dot gnu.org
2022-02-18 21:16 ` pinskia at gcc dot gnu.org
2022-02-22  7:58 ` cvs-commit at gcc dot gnu.org
2022-02-22  7:59 ` cvs-commit at gcc dot gnu.org
2022-02-22  7:59 ` cvs-commit at gcc dot gnu.org
2022-02-22  7:59 ` [Bug tree-optimization/104582] [11 " rguenth at gcc dot gnu.org
2022-04-07  8:15 ` rguenth at gcc dot gnu.org
2022-04-21  7:51 ` rguenth at gcc dot gnu.org
2023-05-29 10:06 ` jakub 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).