[llvm-bugs] [Bug 47575] New: noalias/restrict on global pointers

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 18 02:27:54 PDT 2020


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

            Bug ID: 47575
           Summary: noalias/restrict on global pointers
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

float * __restrict__ x;
float * __restrict__ y;
float * __restrict__ z;



void foo (float * __restrict__ xx, float * __restrict__ yy)
{

 float * __restrict__ pin = &xx[0];
 float * __restrict__ pout =&yy[0];

  *pout++ = *pin++;
  *pout++ = *pin++;
  *pout++ = *pin++;
  *pout++ = *pin++;
}


void bar ()
{

 float * __restrict__ pin = &x[0];
 float * __restrict__ pout =&y[0];

  *pout++ = *pin++;
  *pout++ = *pin++;
  *pout++ = *pin++;
  *pout++ = *pin++;
}



void loop() {
  for (int i=0;i < 4;++i) x[i]=y[i]+z[i];
}


Clang -O3 -mavx2:
foo(float*, float*):                             # @foo(float*, float*)
        vmovups xmm0, xmmword ptr [rdi]
        vmovups xmmword ptr [rsi], xmm0
        ret
bar():                                # @bar()
        mov     rax, qword ptr [rip + x]
        mov     rcx, qword ptr [rip + y]
        mov     edx, dword ptr [rax]
        mov     dword ptr [rcx], edx
        mov     edx, dword ptr [rax + 4]
        mov     dword ptr [rcx + 4], edx
        mov     edx, dword ptr [rax + 8]
        mov     dword ptr [rcx + 8], edx
        mov     eax, dword ptr [rax + 12]
        mov     dword ptr [rcx + 12], eax
        ret
loop():                               # @loop()
        mov     rax, qword ptr [rip + y]
        mov     rcx, qword ptr [rip + z]
        mov     rdx, qword ptr [rip + x]
        vmovss  xmm0, dword ptr [rax]           # xmm0 = mem[0],zero,zero,zero
        vaddss  xmm0, xmm0, dword ptr [rcx]
        vmovss  dword ptr [rdx], xmm0
        vmovss  xmm0, dword ptr [rax + 4]       # xmm0 = mem[0],zero,zero,zero
        vaddss  xmm0, xmm0, dword ptr [rcx + 4]
        vmovss  dword ptr [rdx + 4], xmm0
        vmovss  xmm0, dword ptr [rax + 8]       # xmm0 = mem[0],zero,zero,zero
        vaddss  xmm0, xmm0, dword ptr [rcx + 8]
        vmovss  dword ptr [rdx + 8], xmm0
        vmovss  xmm0, dword ptr [rax + 12]      # xmm0 = mem[0],zero,zero,zero
        vaddss  xmm0, xmm0, dword ptr [rcx + 12]
        vmovss  dword ptr [rdx + 12], xmm0
        ret


GCC:
foo(float*, float*):
        vmovups xmm0, XMMWORD PTR [rdi]
        vmovups XMMWORD PTR [rsi], xmm0
        ret
bar():
        mov     rax, QWORD PTR x[rip]
        vmovups xmm0, XMMWORD PTR [rax]
        mov     rax, QWORD PTR y[rip]
        vmovups XMMWORD PTR [rax], xmm0
        ret
loop():
        mov     rax, QWORD PTR y[rip]
        vmovups xmm0, XMMWORD PTR [rax]
        mov     rax, QWORD PTR z[rip]
        vaddps  xmm0, xmm0, XMMWORD PTR [rax]
        mov     rax, QWORD PTR x[rip]
        vmovups XMMWORD PTR [rax], xmm0
        ret

https://gcc.godbolt.org/z/dPsv17

-- 
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/20200918/50bbd938/attachment.html>


More information about the llvm-bugs mailing list