From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1264B3858425; Tue, 3 Oct 2023 12:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1264B3858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696335552; bh=A+YXB2aBWInFeB1IVpj3eOf99TCyRUXGGbr+MLA2JIE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=byopCLDexWtnMLH94iBaoi2zF5vq95Q+D1RMfsvQ4sMLGoHqKBDBGYFb2NTIjPjo7 /95yfxnRL0AZScKRaGAyoacowSC/I9j4wZYS+KdS05kwLu01F4MBSABPLAaOUjMeev gGY8zn/XHbTi+6qvBbxuAD2oVWMp/lNuPzXYW3Hk= 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:19:11 +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: attachments.created 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 #3 from prathamesh3492 at gcc dot gnu.org --- Created attachment 56037 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56037&action=3Dedit Untested fix The issue is that when a1 is a multiple of vector length, we end up creating following encoding in result: { base_elem, arg[0], arg[1], ... } where arg = is chosen input vector, which is incorrect. For above case, vectorizer pass creates VEC_PERM_EXPR where: arg0: { -16, -9, -10, -11 }=20 arg1: { -12, -5, -6, -7 }=20 sel =3D { 3, 4, 5, 6 } 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_pattern= =3D 3 =3D { -11, -12, -5 } So for res[4], it used S =3D (-5) - (-12) =3D 7 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. 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.=