From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 445E63A1AFFB; Fri, 7 Jun 2024 11:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 445E63A1AFFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1717760646; bh=0sWUP3NEotBWEav06AuZdkQ34ZJz5/1i2z6845HBFF4=; h=From:To:Subject:Date:From; b=JmFQKmQGJmBGqerzHWmNvAJg2PZCIWgHy+EI+b6jY4KnBNEYPxHD8j0/Ar1jLTOiZ 0wT5C9Tomsiee8d9SwR3c9MDHAz2fT6YBM39uZhsklw+sWwIPvHBn861pijC357ICc vDDn4lnAOlE1QzMFwTGWOa+3syO4/KYehbRhtoO4= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115385] New: Peeling for gaps can be optimized more or needs to peel more than one iteration Date: Fri, 07 Jun 2024 11:44:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D115385 Bug ID: 115385 Summary: Peeling for gaps can be optimized more or needs to peel more than one iteration Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- Consider void __attribute__((noipa)) foo(unsigned char * __restrict x, unsigned char *y, int n) { for (int i =3D 0; i < n; ++i) { x[16*i+0] =3D y[3*i+0]; x[16*i+1] =3D y[3*i+1]; x[16*i+2] =3D y[3*i+2]; x[16*i+3] =3D y[3*i+0]; x[16*i+4] =3D y[3*i+1]; x[16*i+5] =3D y[3*i+2]; x[16*i+6] =3D y[3*i+0]; x[16*i+7] =3D y[3*i+1]; x[16*i+8] =3D y[3*i+2]; x[16*i+9] =3D y[3*i+0]; x[16*i+10] =3D y[3*i+1]; x[16*i+11] =3D y[3*i+2]; x[16*i+12] =3D y[3*i+0]; x[16*i+13] =3D y[3*i+1]; x[16*i+14] =3D y[3*i+2]; x[16*i+15] =3D y[3*i+0]; } } and void __attribute__((noipa)) bar(unsigned char * __restrict x, unsigned char *y, int n) { for (int i =3D 0; i < n; ++i) { x[16*i+0] =3D y[5*i+0]; x[16*i+1] =3D y[5*i+1]; x[16*i+2] =3D y[5*i+2]; x[16*i+3] =3D y[5*i+3]; x[16*i+4] =3D y[5*i+4]; x[16*i+5] =3D y[5*i+0]; x[16*i+6] =3D y[5*i+1]; x[16*i+7] =3D y[5*i+2]; x[16*i+8] =3D y[5*i+3]; x[16*i+9] =3D y[5*i+4]; x[16*i+10] =3D y[5*i+0]; x[16*i+11] =3D y[5*i+1]; x[16*i+12] =3D y[5*i+2]; x[16*i+13] =3D y[5*i+3]; x[16*i+14] =3D y[5*i+4]; x[16*i+15] =3D y[5*i+0]; } } for both loops we currently cannot reduce the access for the load from 'y' = to not touch extra elements so we force peeling for gaps. But in both cases peeling a single scalar iteration is not sufficient and we get t.c:5:21: note: =3D=3D> examining statement: _3 =3D y[_1]; t.c:5:21: missed: peeling for gaps insufficient for access t.c:7:20: missed: not vectorized: relevant stmt not supported: _3 =3D y[_= 1]; we can avoid this excessive peeling for gaps if we narrow the load from 'y' to the next power-of-two size where then it's always sufficient to just peel a single scalar iteration. When the target cannot construct a vector with those elements we'd have to peel more than one iteration.=