From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9ACE53858C27; Mon, 11 Apr 2022 14:09:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ACE53858C27 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/105197] [12 Regression] SVE: wrong code with -O -ftree-vectorize Date: Mon, 11 Apr 2022 14:09:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: tnfchris at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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: Mon, 11 Apr 2022 14:09:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105197 --- Comment #5 from CVS Commits --- The master branch has been updated by Tamar Christina : https://gcc.gnu.org/g:78c718490bc2843d4dadcef8a0ae14aed1d15a32 commit r12-8080-g78c718490bc2843d4dadcef8a0ae14aed1d15a32 Author: Tamar Christina Date: Mon Apr 11 15:09:05 2022 +0100 middle-end: Prevent the use of the cond inversion detection code when b= oth conditions are external. [PR105197] Previously ifcvt used to enforce that a mask A and the inverse of said = mask be represented as ~A. So for the masks _25 =3D _6 !=3D 0; _44 =3D _4 !=3D 0; ifcvt would produce for an operation requiring the inverse of said mask _26 =3D ~_25; _43 =3D ~_44; but now that VN is applied to the entire function body we get a simplification on the mask and produce: _26 =3D _6 =3D=3D 0; _43 =3D _4 =3D=3D 0; This in itself is not a problem semantically speaking (though it does create more masks that need to be tracked) but when vectorizing the masked conditional we would still detect _26 and _43 to be inverses of _25 and _44 and mark them as requiring their operands be swapped. When vectorizing we swap the operands but don't find the BIT_NOT_EXPR to remove and so we leave the condition as is which produces invalid code: ------>vectorizing statement: _ifc__41 =3D _43 ? 0 : _ifc__40; created new init_stmt: vect_cst__136 =3D { 0, ... } add new stmt: _137 =3D mask__43.26_135 & loop_mask_111 note: add new stmt: vect__ifc__41.27_138 =3D VEC_COND_EXPR <_137, vect__ifc__40.25_133, vect_cst__136>; This fixes disabling the inversion detection code when the loop isn't masked since both conditional would be external. We'd then not use the new cond_code and would incorrectly still swap the operands. The resulting code is also better than GCC-11 with most operations now predicated on the loop mask rather than a ptrue. gcc/ChangeLog: PR target/105197 * tree-vect-stmts.cc (vectorizable_condition): Prevent cond swap when not masked. gcc/testsuite/ChangeLog: PR target/105197 * gcc.target/aarch64/sve/pr105197-1.c: New test. * gcc.target/aarch64/sve/pr105197-2.c: New test.=