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.
  • [Bug tree-optimization/1... 652023330028 at smail dot nju.edu.cn via Gcc-bugs

Reply via email to