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

            Bug ID: 24056
           Summary: memcpy and memmove are lowered the same way
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PTX
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

In NVPTXLowerAggrCopies, NVPTX lowers llvm.memcpy and llvm.memmove in exactly
the same way, by producing load-store loops counting up. Here's a sample
lowering to PTX:

    ld.param.u64     %rd2, [_Z11foo_memmovePfS_j_param_0];
    ld.param.u64     %rd3, [_Z11foo_memmovePfS_j_param_1];
    ld.param.u32     %rd1, [_Z11foo_memmovePfS_j_param_2];
    mov.u64     %rd9, 0;
LBB1_1:
    add.s64     %rd7, %rd2, %rd9;
    ld.u8     %rs1, [%rd7];
    add.s64     %rd8, %rd3, %rd9;
    st.u8     [%rd8], %rs1;
    add.s64     %rd9, %rd9, 1;
    setp.lt.u64    %p1, %rd9, %rd1;
    @%p1 bra     LBB1_1;
    ret;

This is incorrect for memmove, which guarantees to work correctly when the
ranges of source and destination overlap. If source starts lower than dest and
there's an overlap, the result will be incorrect.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to