public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "absoler at smail dot nju.edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114236] New: introduce unnecessary store operation when unrolling a loop
Date: Tue, 05 Mar 2024 11:54:35 +0000	[thread overview]
Message-ID: <bug-114236-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114236
           Summary: introduce unnecessary store operation when unrolling a
                    loop
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

here's the code, compiled with gcc-13.2.0 -O2
```
// https://godbolt.org/z/5xWrr44hn
short g_16[2][1] = {{(-8L)},{(-8L)}};
int g_22 = (-1L);
int g_71 = 0xA62A9801L;
int *g_70 = &g_71;

int c;
void func_1() {
  int d;
  for (; c;)
    ;
  for (d = -1; d < 17; d++) {
    short *e = g_16[0];
    *g_70 = *e = g_22;
  }
}

```
```
func_1():
  401440:       mov    0x10762(%rip),%eax        # 411ba8 <c>
  401446:       test   %eax,%eax
  401448:       je     401450 <func_1+0x10>
  40144a:       jmp    40144a <func_1+0xa>
  40144c:       nopl   0x0(%rax)

  401450:       mov    0x2c09(%rip),%rsi        # 404060 <g_70>
  401457:       mov    $0x12,%eax
  40145c:       nopl   0x0(%rax)
  401460:       mov    0x2c06(%rip),%ecx        # 40406c <g_22>
  401466:       movswl %cx,%edx
  401469:       mov    %edx,(%rsi)

  40146b:       sub    $0x1,%eax
  40146e:       jne    401460 <func_1+0x20>
  401470:       mov    %cx,0x2bf9(%rip)        # 404070 <g_16>
  401477:       mov    %edx,(%rsi)
```
we can see that the store operation at 0x401477 is unnecessary and lead to 19
times memory write, more one time than the loop.
And I found this behavior showing up from the `141t.lim2` file when I check the
output files of `-fdump-tree-all`.

             reply	other threads:[~2024-03-05 11:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 11:54 absoler at smail dot nju.edu.cn [this message]
2024-03-05 15:17 ` [Bug tree-optimization/114236] " rguenth 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-114236-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: link
Be 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).