public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114823] New: Missed optimization of redundant loops
@ 2024-04-23 10:11 652023330028 at smail dot nju.edu.cn
  2024-04-23 15:53 ` [Bug tree-optimization/114823] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-23 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114823
           Summary: Missed optimization of redundant loops
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, for the reduced code below, its second loop is redundant. There seems to
be a missed optimization.

https://godbolt.org/z/McqeYdnfY

int a[1024];
int b[1024];

void func()
{
    for (int i = 0; i < 1024; i+=1) {
        a[i] = b[i] * 2;
    }

    for (int i = 0; i < 1024; i+=1) {
        a[i] = b[i] * 2;
    }
}

GCC -O3:
func:
        xor     eax, eax
.L2:
        movdqa  xmm0, XMMWORD PTR b[rax]
        add     rax, 16
        pslld   xmm0, 1
        movaps  XMMWORD PTR a[rax-16], xmm0
        cmp     rax, 4096
        jne     .L2
        xor     eax, eax
.L3:
        movdqa  xmm0, XMMWORD PTR b[rax]
        add     rax, 16
        pslld   xmm0, 1
        movaps  XMMWORD PTR a[rax-16], xmm0
        cmp     rax, 4096
        jne     .L3
        ret

Expected code:
func:
        xor     eax, eax
.L2:
        movdqa  xmm0, XMMWORD PTR b[rax]
        add     rax, 16
        pslld   xmm0, 1
        movaps  XMMWORD PTR a[rax-16], xmm0
        cmp     rax, 4096
        jne     .L2
        ret

Thank you very much for your time and effort! We look forward to hearing from
you.

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

* [Bug tree-optimization/114823] Missed optimization of redundant loops
  2024-04-23 10:11 [Bug tree-optimization/114823] New: Missed optimization of redundant loops 652023330028 at smail dot nju.edu.cn
@ 2024-04-23 15:53 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-23 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-23

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  loop fusion would detect the redundancy.

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

end of thread, other threads:[~2024-04-23 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 10:11 [Bug tree-optimization/114823] New: Missed optimization of redundant loops 652023330028 at smail dot nju.edu.cn
2024-04-23 15:53 ` [Bug tree-optimization/114823] " 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).