From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD1773858D33; Mon, 15 Mar 2021 08:46:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD1773858D33 From: "eggert at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/99591] New: Improving __builtin_add_overflow performance on x86-64 Date: Mon, 15 Mar 2021 08:46:29 +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: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eggert at gnu dot org 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: Mon, 15 Mar 2021 08:46:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99591 Bug ID: 99591 Summary: Improving __builtin_add_overflow performance on x86-64 Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: eggert at gnu dot org Target Milestone: --- This is with gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9) on x86-64. For the function: _Bool signed1_overflow (signed char a, signed char b) { signed char r; return __builtin_add_overflow (a, b, &r); } gcc generates the code: signed1_overflow: movsbl %sil, %esi movsbl %dil, %edi addb %sil, %dil seto %al ret The movsbl instructions are unnecessary and can be omitted. For the function: _Bool signed2_overflow (short a, short b) { short r; return __builtin_add_overflow (a, b, &r); } gcc generates: signed2_overflow: movswl %di, %edi movswl %si, %esi xorl %eax, %eax addw %si, %di jo .L8 .L6: andl $1, %eax ret .L8: movl $1, %eax jmp .L6 Better would be this: signed2_overflow: addw %si, %di seto %al retq There are similar opportunities for improvement in __builtin_sub_overflow a= nd __builtin_mul_overflow. This bug report follows up on this discussion about Gnulib: https://lists.gnu.org/r/bug-gnulib/2021-03/msg00078.html https://lists.gnu.org/r/bug-gnulib/2021-03/msg00079.html https://lists.gnu.org/r/bug-gnulib/2021-03/msg00080.html=