public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114236] New: introduce unnecessary store operation when unrolling a loop
@ 2024-03-05 11:54 absoler at smail dot nju.edu.cn
  2024-03-05 15:17 ` [Bug tree-optimization/114236] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-03-05 11:54 UTC (permalink / raw)
  To: gcc-bugs

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`.

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

* [Bug tree-optimization/114236] introduce unnecessary store operation when unrolling a loop
  2024-03-05 11:54 [Bug tree-optimization/114236] New: introduce unnecessary store operation when unrolling a loop absoler at smail dot nju.edu.cn
@ 2024-03-05 15:17 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-05 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Executing store motion of MEM[(short int *)&g_16] from loop 2
Re-issueing dependent store of *g_70.2_4 from loop 2 on exit 4 -> 5
Moving statement

The extra store is required to enable sinking of the store to g_16 as
we don't know whether g_70 points to aliased memory.

I think we fail to realize that *g_70 is loop invariant as well, but
what you observe is a feature - it allows reducing the number of stores
to g_16.

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

end of thread, other threads:[~2024-03-05 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 11:54 [Bug tree-optimization/114236] New: introduce unnecessary store operation when unrolling a loop absoler at smail dot nju.edu.cn
2024-03-05 15:17 ` [Bug tree-optimization/114236] " 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).