From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1D58D3858C2C; Tue, 3 Oct 2023 12:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D58D3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696335702; bh=GnLp76Ko8Qu1dtVK2R0whQCPm9o/t1ViZZ4PXH3QJuM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iDrb22EaFxe7iHauAmEkSJqTf4EgvsPrQE73ID4mRcVZse/NfRGLqFPdY9rxrvYI7 X/sKKUk2SKwqwXIA/9F++GdM263wO8ueWxFOh1QqCOLwyb1Lu4VRQ0vA09PAsSozya VyXyPxY8GsLGd4UGfMyblOlXLRl3DBQdz+aGmNBk= From: "prathamesh3492 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111648] [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since r14-3243-ga7dba4a1c05 Date: Tue, 03 Oct 2023 12:21:41 +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: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: prathamesh3492 at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: prathamesh3492 at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111648 --- Comment #4 from prathamesh3492 at gcc dot gnu.org --- (In reply to prathamesh3492 from comment #3) > Created attachment 56037 [details] > Untested fix >=20 > The issue is that when a1 is a multiple of vector length, we end up creat= ing > following encoding in result: { base_elem, arg[0], arg[1], ... } where arg > is chosen input vector, which is incorrect. >=20 > For above case, vectorizer pass creates VEC_PERM_EXPR whe= re: > arg0: { -16, -9, -10, -11 }=20 > arg1: { -12, -5, -6, -7 }=20 > sel =3D { 3, 4, 5, 6 } >=20 > arg0, arg1 and sel are encoded with npatterns =3D 1 and nelts_per_pattern= =3D 3. > Since a1 =3D 4 and arg_len =3D 4, it ended up creating the result with > following encoding: > res =3D { arg0[3], arg1[0], arg1[1] } // npatterns =3D 1, nelts_per_patte= rn =3D 3 > =3D { -11, -12, -5 } >=20 > So for res[4], it used S =3D (-5) - (-12) =3D 7 Typo: I meant res[3], not res[4]. Sorry. > And hence computed it as -5 + 7 =3D 2. > instead of arg1[2], ie, -6. > which is the difference we see in output at -O0 vs -O2. >=20 > The patch tweaks the constratints in valid_mask_for_fold_vec_perm_cst_p to > punt if a1 is a multiple of vector length, so a1 ... ae only selects from > stepped part of the input vector, which seems to fix this issue. > I will run a proper bootstrap+test and post it upstream.=