From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C60B43858D38; Mon, 27 Jul 2020 01:27:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C60B43858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595813274; bh=LM8DJpvC5Y8SPd7YfFvNS3ucWjh/+lSQx4TKl21vdDQ=; h=From:To:Subject:Date:From; b=WZns2XYmNKzyzAZScr99VSNUqoiAxDnLBzzGlF/byvavL8lkqmFVL9zJIc3rnM9Qi +FGejEH7DhDK7kKIFuuUgUUn+dU0lRwHF0T/Zl3wofd1acGst0Sc6/GHDp/xZO/mGt 7S/4iGElxp9puAEUYFf7wxAtV/Hbr7AuOGFIwyn0= From: "pterjan at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/96326] New: Incorrect loop optimization at -O3 Date: Mon, 27 Jul 2020 01:27:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pterjan at gmail dot com 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 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: Mon, 27 Jul 2020 01:27:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96326 Bug ID: 96326 Summary: Incorrect loop optimization at -O3 Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pterjan at gmail dot com Target Milestone: --- Found in https://github.com/Sereal/Sereal/issues/229 #include #include int main() { char buf[128]; char *src =3D buf; char *op =3D buf + 3; int len =3D 64; strcpy(buf, "abc"); while (op - src < 8) { *(unsigned long*)op =3D *(const unsigned long*)src; len -=3D op - src; op +=3D op - src; } while (len > 0) { *(unsigned long*)op =3D *(const unsigned long*)src; src +=3D 8; op +=3D 8; len -=3D 8; } printf("%ld\n", strlen(buf)); } $ gcc -O2 -Wall t.c; ./a.out=20 68 $ gcc -O3 -Wall t.c; ./a.out=20 24 Adding a printf in the second loop also fixes it.=