From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 78A20385DC23; Thu, 23 Apr 2020 14:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78A20385DC23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587653157; bh=ZI/mXU4iL9/wfWPbAxPrD3Ca+ALehzUIH0yjodx/tWE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qOFW1siYdsttFHhWpuAm60O/vuiLriPjsUFFl/eQjrfz/wbarkZdfA0RXUhH8sLb9 9bq+8EfKNHB33bi7mRHoiI0KPccG6kPuXWgaCQrDl4U+Rs+/7QuRTrl9T+Ed3D2CWY R5oocRcHheCJa983sPB2V3ypgyhBYmOWkjfUXWDg= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94727] [10 Regression] GCC produces incorrect code with -O3 since r10-5071-g02d895504cc59be0 Date: Thu, 23 Apr 2020 14:45:57 +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.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: rsandifo at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.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: Thu, 23 Apr 2020 14:45:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94727 --- Comment #8 from CVS Commits --- The master branch has been updated by Richard Sandiford : https://gcc.gnu.org/g:901f5289d9465d4c388ae288f850ad4f29e99a2c commit r10-7915-g901f5289d9465d4c388ae288f850ad4f29e99a2c Author: Richard Sandiford Date: Thu Apr 23 15:45:43 2020 +0100 vect: Fix comparisons between invariant booleans [PR94727] This PR was caused by mismatched expectations between vectorizable_comparison and SLP. We had a "<" comparison between two booleans that were leaves of the SLP tree, so vectorizable_comparison fell back on: /* Invariant comparison. */ if (!vectype) { vectype =3D get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), slp_node); if (maybe_ne (TYPE_VECTOR_SUBPARTS (vectype), nunits)) return false; } rhs1 and rhs2 were *unsigned* boolean types, so we got back a vector of unsigned integers. This in itself was OK, and meant that "<" worked as expected without the need for the boolean fix-ups: /* Boolean values may have another representation in vectors and therefore we prefer bit operations over comparison for them (which also works for scalar masks). We store opcodes to use in bitop1 and bitop2. Statement is vectorized as BITOP2 (rhs1 BITOP1 rhs2) or rhs1 BITOP2 (BITOP1 rhs2) depending on bitop1 and bitop2 arity. */ bool swap_p =3D false; if (VECTOR_BOOLEAN_TYPE_P (vectype)) { However, vectorizable_comparison then used vect_get_slp_defs to get the actual operands. The request went to vect_get_constant_vectors, which also has logic to calculate the vector type. The problem was that this type was different from the one chosen above: if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op)) && vect_mask_constant_operand_p (stmt_vinfo)) vector_type =3D truth_type_for (stmt_vectype); else vector_type =3D get_vectype_for_scalar_type (vinfo, TREE_TYPE (op), op_node); So the function gave back a vector of mask types, which here are vectors of *signed* booleans. This meant that "<" gave: true (-1) < false (0) and so the boolean fixup above was needed after all. Fixed by making vectorizable_comparison also pick a mask type in this case. 2020-04-23 Richard Sandiford gcc/ PR tree-optimization/94727 * tree-vect-stmts.c (vectorizable_comparison): Use mask_type wh= en comparing invariant scalar booleans. gcc/testsuite/ PR tree-optimization/94727 * gcc.dg/vect/pr94727.c: New test.=