From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CCE313858D20; Thu, 17 Feb 2022 12:30:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCE313858D20 From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/104582] New: Unoptimal code for __negdi2 (and others) from libgcc2 Date: Thu, 17 Feb 2022 12:30:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Feb 2022 12:30:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104582 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__ !=3D __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 =3D {.ll =3D u}; const DWunion w =3D { {.low =3D -uu.s.low, .high =3D -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=