From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 09A153851C34; Thu, 2 Sep 2021 09:26:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09A153851C34 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99591] Improving __builtin_add_overflow performance on x86-64 Date: Thu, 02 Sep 2021 09:26:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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, 02 Sep 2021 09:26:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99591 --- Comment #7 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:2af6dd77ea742d4ee911f466878624972929508a commit r12-3312-g2af6dd77ea742d4ee911f466878624972929508a Author: Jakub Jelinek Date: Thu Sep 2 11:25:07 2021 +0200 match.pd: Demote IFN_{ADD,SUB,MUL}_OVERFLOW operands [PR99591] The overflow builtins work on infinite precision integers and then conv= ert to the result type's precision, so any argument promotions are useless. The expand_arith_overflow expansion is able to demote the arguments its= elf through get_range_pos_neg and get_min_precision calls and if needed pro= mote to whatever mode it decides to perform the operations in, but if there = are any promotions it demoted, those are already expanded. Normally combine would remove the useless sign or zero extensions when it sees the result of those is only used in a lowpart subreg, but typically those lowpart subregs appear multiple times in the pattern so that they describe prop= erly the overflow behavior and combine gives up, so we end up with e.g. movswl %si, %esi movswl %di, %edi imulw %si, %di seto %al where both movswl insns are useless. The following patch fixes it by demoting operands of the ifns (only gets rid of integral to integral conversions that increase precision). While IFN_{ADD,MUL}_OVERFLOW are commutative and just one simplify woul= d be enough, IFN_SUB_OVERFLOW is not, therefore two simplifications. 2021-09-02 Jakub Jelinek PR tree-optimization/99591 * match.pd: Demote operands of IFN_{ADD,SUB,MUL}_OVERFLOW if th= ey were promoted. * gcc.target/i386/pr99591.c: New test. * gcc.target/i386/pr97950.c: Match or reject setb or jn?b instructions together with seta or jn?a.=