From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2724F39551C5; Thu, 23 Apr 2020 10:26:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2724F39551C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587637583; bh=VahgZbz9pYoIMzJupkHMJ7EZhkVerLHDUEXZQurSomI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hc3ffyifkJJThAl6wfO9bGij4LOTH19PTxyQxkJZPdvq7PSbOxhL+lWiaT6IFwpnH Hrjm0fzuJiLMr4Qgyb9el0o4k53nPyi3ozmzuHQHA0LOj21UYoiNYRscnjHQuUYhmL vVr+xx01zFJGf/gAQOxjcnxQ5eMth4caff+YTeIA= From: "rsandifo 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 10:26:22 +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: rsandifo 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 10:26:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94727 --- Comment #5 from rsandifo at gcc dot gnu.org --- Well, this is a bit of mess (surprise). We have a "<" comparison between two booleans that are leaves of the SLP tree, so vectorizable_comparison falls 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 are *unsigned* boolean types, so we get back a vector of unsigned integers. All is well, and "<" works as expected without the need for: /* 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, we then defer to vect_get_slp_defs to get the actual operands. The expected vector type is not part of this interface. The request goes to vect_get_constant_vectors, which does: 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 gives back a vector of mask types, which here are vectors of *signed* booleans. This means that "<" gives: true (-1) < false (0) and so the boolean fixup above was needed after all. I'm going to try: diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 7f3a9fb5fb3..88a1e2c51d2 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -10566,8 +10566,11 @@ vectorizable_comparison (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, /* Invariant comparison. */ if (!vectype) { - vectype =3D get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), - slp_node); + if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (rhs1))) + vectype =3D mask_type; + else + vectype =3D get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), + slp_node); if (!vectype || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype), nunits)) return false; } which does at least fix the testcase.=