From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9CC863860C3F; Thu, 27 May 2021 14:03:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CC863860C3F From: "jl_gccbugs at conductive dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning Date: Thu, 27 May 2021 14:03:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jl_gccbugs at conductive dot de 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 cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2021 14:03:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100801 Bug ID: 100801 Summary: Aggressive loop optimizations cause incorrect warning Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: jl_gccbugs at conductive dot de CC: marxin at gcc dot gnu.org Target Milestone: --- The following warning is triggered > $ gcc-11 -c constproploopopt.c -O2 -Wall -mavx -g > constproploopopt.c: In function =E2=80=98test=E2=80=99: > constproploopopt.c:22:18: warning: iteration 4611686018427387903 invokes = undefined behavior [-Waggressive-loop-optimizations] > 22 | dest[i] =3D src[i]; > | ^ > constproploopopt.c:21:12: note: within this loop > 21 | for (; i < count; ++i) { // handle residual elements > | ~~^~~~~~~ by this (minimal) code: > #include > #include > #if defined(_MSC_VER) > #include > #else > #include > #endif >=20 > void copy_32_unaligned(uint32_t* dest, const uint32_t* src, size_t count)= { > // invariant/nop > __m128i shufmask =3D _mm_set_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, = 5, 4, 3, 2, 1, 0); >=20 > size_t i; > for (i =3D 0; i + 4 <=3D count; i +=3D 4) { > __m128i input =3D _mm_loadu_si128((const __m128i*)(&src[i])); > __m128i output =3D input; > // no warning without the shuffle: > output =3D _mm_shuffle_epi8(input, shufmask); > _mm_storeu_si128((__m128i*)(&dest[i]), output); > } > for (; i < count; ++i) { // handle residual elements > dest[i] =3D src[i]; > } > } >=20 > void test(uint32_t* buf1, uint32_t* buf2) { > copy_32_unaligned(buf2, buf1, > // multiples of 4 and greater or equal then 12 trig= ger it: > 12); > } >>From objdump output I believe the generated code is correct though. The war= ning seems to be incorrect in this context, especially since the "residual" loop should be skipped for count=3Dn*4 anyways.=