From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3AAAF3858417; Wed, 26 Jul 2023 10:32:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AAAF3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690367542; bh=t9pH02YxqDtZvPq2j08c+HJw/3ubzZUiJL+VeO0WXVg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c+WzCZ/QhyUU4kRTK0d7LxiKgnrpfXvab9hWi+V37j30s3smk3nAUVQpEW6JI77Q0 AGA+miroxmqjxm4KA3medj3KsHH8mea4DBVGQHirpVBdDA1ULG8NUfjI0zLNRjiyTz gvY/fzEqfWGTfF3FJizGShOjWh9H3pUiirciHyRE= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/106081] missed vectorization Date: Wed, 26 Jul 2023 10:32:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106081 --- Comment #11 from Richard Biener --- (In reply to rsandifo@gcc.gnu.org from comment #10) > (In reply to Richard Biener from comment #9) [...] > > The following elides the unnecessary permutation for this special case > > (but not the general case): > >=20 > > diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc > > index e4430248ab5..e9048a61891 100644 > > --- a/gcc/tree-vect-slp.cc > > +++ b/gcc/tree-vect-slp.cc > > @@ -4389,6 +4389,19 @@ vect_optimize_slp_pass::change_layout_cost (slp_= tree > > node, > > if (from_layout_i =3D=3D to_layout_i) > > return 0; > >=20=20 > > + /* When there's a uniform load permutation permutating that in any > > + way is free. */ > > + if (SLP_TREE_LOAD_PERMUTATION (node).exists ()) > > + { > > + unsigned l =3D SLP_TREE_LOAD_PERMUTATION (node)[0]; > > + unsigned i; > > + for (i =3D 1; i < SLP_TREE_LOAD_PERMUTATION (node).length (); ++= i) > > + if (SLP_TREE_LOAD_PERMUTATION (node)[i] !=3D l) > > + break; > > + if (i =3D=3D SLP_TREE_LOAD_PERMUTATION (node).length ()) > > + return 0; > > + } > > + > > auto_vec children (1); > > children.quick_push (node); > > auto_lane_permutation_t perm (SLP_TREE_LANES (node)); > >=20 > > I'm not sure this is the correct place to factor in cost savings > > materialization would give. Is it? > Yeah, I think so. The patch LGTM. I don't know if it's worth > caching the =E2=80=9Call the same element=E2=80=9D result, but probably n= ot. Yeah, I thought of changing the load_permutation representation to vec_perm_indices but then as I consider merging lane and load permutes that would be wrong step. I've thought of generalizing the above but then change_layout_cost is always positive but for example when doing { 3, 2, 1, 0 } ontop an existing load permutation of { 3, 2, 1, 0 } the cost should be negative? Anyway, going to test the above patch.=