[llvm-bugs] [Bug 33785] New: Wrong register in result asm when using inline asm with movups

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 14 08:23:44 PDT 2017


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

            Bug ID: 33785
           Summary: Wrong register in result asm when using inline asm
                    with movups
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ilia.taraban at intel.com
                CC: llvm-bugs at lists.llvm.org

==================== copy-asm.c =================
#include <stdio.h>
#define N 2


float  __declspec(align(64)) farray[4 * N];
float  __declspec(align(64)) fdest[4 * N];


void copy_from_arr_to_dest()
{
    long long int i;

    for (i = 0; i < sizeof(farray); i += 4) {
        __asm {
            mov  rax, i
            movups xmm1, [farray+rax]
            movups [fdest+rax], xmm1
        }
    }
}


int
main()
{
    int i;
    for (i = 0; i < 4 * N; ++i) {
        farray[i] = (float)i;
    }

    copy_from_arr_to_dest();
    //check second pack of floats
    if (fdest[4] != farray[4]) {
       printf("FAILED\n");
       return 1;
    }
    printf("PASSED!\n");
    return 0;
}
====================================================

>>> clang -v
clang version 5.0.0 (cfe/trunk 307600)
...

>>> clang -o copy-asm.exe copy-asm.c -fms-extensions
>>> ./copy-asm.exe
FAILED


=============== generated-assembler =================
...
        movq    -8(%rbp), %rax           # mov  rax, i
        movups  farray(%rip), %xmm1      # movups xmm1, [farray+rax]
        movups  %xmm1, fdest(%rip)       # movups [fdest+rax], xmm1
...
=====================================================

Now, if we change rip to rax(which we use in inline asm block):

=============== new-assembler =================
...
        movq    -8(%rbp), %rax           # mov  rax, i
        movups  farray(%rax), %xmm1      # movups xmm1, [farray+rax]
        movups  %xmm1, fdest(%rax)       # movups [fdest+rax], xmm1
...
=====================================================
>>> clang -o fixed-copy-asm.exe fixed-copy-asm.s
>>> ./fixed-copy-asm.exe
PASSED!

Same problem with movaps, movdqa32, movdqu32
------------------------
Intel Software Engineer
Ilia Taraban

-- 
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/20170714/311d40d0/attachment.html>


More information about the llvm-bugs mailing list