From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B9EA23857837; Thu, 11 Jan 2024 09:13:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9EA23857837 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704964403; bh=tW4BWlAsfZP4vmxEPx/6WJIyaUn9jzs8+640ss+CU5Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=onGVUkKzr+0muOb40/n4byGwpOkNQCplodxA9PEQfLja09Py46pjOuyuG7SAO3nsC C8iPcCXDxO0aF29XaWhuQyEnprGxnVcGqTW8adSbyHLTOBWX+tz9JXOyuwGKpHPYvj 1HGeDh9gPtg0arGV6zbhqoJx3vnTqIuzPJgx1joY= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/113326] Optimize vector shift with constant delta on shifting-count operand Date: Thu, 11 Jan 2024 09:13:23 +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: unknown X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned 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=3D113326 --- Comment #6 from Richard Biener --- (In reply to Andrew Pinski from comment #5) > One more thing: > ``` > vect_shift_0 =3D vect_value >> { 0, 1, 2, 3 }; > vect_shift_1 =3D vect_value >> { 4, 5, 6, 7 }; > vect_shift_2 =3D vect_value >> { 8, 9, 10, 11 }; > vect_shift_3 =3D vect_value >> { 12, 13, 14, 15 }; > ``` > vs > ``` > vect_shift_0 =3D vect_value >> { 0, 1, 2, 3 }; > vect_shift_1 =3D vect_shift_0 >> { 4, 4, 4, 4 }; > vect_shift_2 =3D vect_shift_0 >> { 8, 8, 8, 8 }; > vect_shift_3 =3D vect_shift_0 >> { 12, 12, 12, 12 }; > ``` >=20 > the first has fully independent operations while in the second case, there > is one dependent and the are independent operations. >=20 > On cores which has many vector units the first one might be faster than t= he > second one. So this needs a cost model too. Note the vectorizer has the shift values dependent as well (across iteratio= ns), we just constant propagate after unrolling here. Note this is basically asking for "strength-reduction" of expensive constants which could be more generally useful and not only for this specific shift case. Consider the same example but with an add instead of a shift for example, the same exact set of constants will appear.=