public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "carrot at google dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/62147] New: missed loop counter based optimization Date: Fri, 15 Aug 2014 00:14:00 -0000 [thread overview] Message-ID: <bug-62147-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62147 Bug ID: 62147 Summary: missed loop counter based optimization Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: carrot at google dot com Target: powerpc64le Compile following source code with options -m64 -mcpu=power8 -O2 typedef struct { int l; int b[258]; } S; void clear (S* s ) { int i; int len = s->l + 1; // int len = s->l; for (i = 0; i <= len; i++) s->b[i] = 0; } Trunk compiler generates: clear: lwz 9,0(3) cmpwi 7,9,-1 bltlr- 7 addi 9,9,1 li 10,0 rldicl 9,9,0,32 addi 9,9,1 sldi 9,9,2 add 9,3,9 .p2align 4,,15 .L3: stwu 10,4(3) cmpld 7,3,9 bne+ 7,.L3 blr It uses cmp/jmp instructions to construct the loop, a better code sequence should use the bdnz instruction. If I change the source code as in the comment, gcc can generate bdnz instruction to form the loop clear: lwz 9,0(3) cmpwi 7,9,0 extsw 9,9 bltlr- 7 sldi 9,9,2 li 10,0 srdi 9,9,2 addi 9,9,1 mtctr 9 .p2align 4,,15 .L3: stwu 10,4(3) bdnz .L3 blr
next reply other threads:[~2014-08-15 0:14 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-08-15 0:14 carrot at google dot com [this message] 2014-08-15 0:26 ` [Bug target/62147] " pinskia at gcc dot gnu.org 2014-08-16 18:29 ` segher at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-62147-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).