From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4046C398A49E; Sat, 31 Jul 2021 00:41:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4046C398A49E From: "matthijsvanduin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100801] Aggressive loop optimizations cause incorrect warning Date: Sat, 31 Jul 2021 00:41:45 +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: 11.1.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: matthijsvanduin at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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 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: Sat, 31 Jul 2021 00:41:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100801 Matthijs van Duin changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matthijsvanduin at gmail d= ot com --- Comment #3 from Matthijs van Duin --- Simpler testcase: /* compiler flags required to trigger warning: -O1 -ftree-vrp */ static void foo(int *x, long n) { long i =3D 0; for (; i + 4 <=3D n; i +=3D 4) { } for (; i < n; i++) { x[i]++; } } void bar(int *x) { foo(x, 128); } A workaround with no runtime overhead is adding the following check between= the loops: if (__builtin_constant_p(n % 4 =3D=3D 0) && n % 4 =3D=3D 0) return;=