[llvm-bugs] [Bug 46335] New: Wrong code generated for simple memory move loop

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 15 18:44:33 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46335

            Bug ID: 46335
           Summary: Wrong code generated for simple memory move loop
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

Compile following code with -O2

typedef struct SS
{
  int d[3];
  int a[6][4];
} S;

void foo(int d, S *p) 
{
    int i;
    for (i = 0; i < 3; i++)
    {   
      p->a[d][i] = p->a[d][i+1];
    }   
}

I got:

# %bb.0:                                # %entry
        movslq  %edi, %rax
        shlq    $4, %rax
        movl    24(%rax,%rsi), %ecx
        movl    %ecx, 20(%rsi,%rax)          // over written before read out
        movq    16(%rax,%rsi), %rcx
        movq    %rcx, 12(%rsi,%rax)
        retq

The 4 bytes word at 20(%rsi,%rax) is over written before read out, causes wrong
result at 16(%rsi,%rax).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200616/90475499/attachment.html>


More information about the llvm-bugs mailing list