public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.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 12:35:43 +0000 [thread overview] Message-ID: <bug-94727-4-F3BKIa8M8B@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-94727-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94727 --- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to rsandifo@gcc.gnu.org from comment #5) > 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 = 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 = 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. Ah yeah - sth on my list to fix (not making the type part of that API but assigning vector types to SLP nodes). I even have partly completed "hacks" to do that. When we have (and use!) vector types on all SLP nodes we can also get rid of the mismatch code. > 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 = truth_type_for (stmt_vectype); > else > vector_type = 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 = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), > - slp_node); > + if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (rhs1))) > + vectype = mask_type; > + else > + vectype = 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. LGTM.
next prev parent reply other threads:[~2020-04-23 12:35 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-23 5:14 [Bug tree-optimization/94727] New: GCC produces incorrect code with -O3 vsevolod.livinskij at frtk dot ru 2020-04-23 5:35 ` [Bug tree-optimization/94727] [10 Regression] GCC produces incorrect code with -O3 since r10-5071-g02d895504cc59be0 marxin at gcc dot gnu.org 2020-04-23 6:44 ` rguenth at gcc dot gnu.org 2020-04-23 7:02 ` rguenth at gcc dot gnu.org 2020-04-23 7:34 ` rsandifo at gcc dot gnu.org 2020-04-23 10:26 ` rsandifo at gcc dot gnu.org 2020-04-23 12:35 ` rguenth at gcc dot gnu.org [this message] 2020-04-23 13:02 ` rsandifo at gcc dot gnu.org 2020-04-23 14:45 ` cvs-commit at gcc dot gnu.org 2020-04-23 14:48 ` rsandifo at gcc dot gnu.org 2020-04-28 7:04 ` cvs-commit at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94727-4-F3BKIa8M8B@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).