public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96326] New: Incorrect loop optimization at -O3
@ 2020-07-27  1:27 pterjan at gmail dot com
  2020-07-27  1:36 ` [Bug middle-end/96326] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pterjan at gmail dot com @ 2020-07-27  1:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96326

            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 <string.h>
#include <stdio.h>

int main() {
        char buf[128];
        char *src = buf;
        char *op = buf + 3;
        int len = 64;
        strcpy(buf, "abc");
        while (op - src < 8) {
                *(unsigned long*)op = *(const unsigned long*)src;
                len -= op - src;
                op += op - src;
        }
        while (len > 0) {
                *(unsigned long*)op = *(const unsigned long*)src;
                src += 8;
                op += 8;
                len -= 8;
        }
        printf("%ld\n", strlen(buf));
}

$ gcc -O2 -Wall t.c; ./a.out 
68

$ gcc -O3 -Wall t.c; ./a.out 
24

Adding a printf in the second loop also fixes it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-27  7:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27  1:27 [Bug c/96326] New: Incorrect loop optimization at -O3 pterjan at gmail dot com
2020-07-27  1:36 ` [Bug middle-end/96326] " pinskia at gcc dot gnu.org
2020-07-27  1:48 ` pterjan at gmail dot com
2020-07-27  6:41 ` [Bug middle-end/96326] [10/11 Regression] Incorrect loop optimization at -O3 since r10-4803-g8489e1f45b50600c marxin at gcc dot gnu.org
2020-07-27  7:43 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).