llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

incorrect code generation for inlined memcpy()

Open llvmbot opened this issue 14 years ago • 4 comments

Bugzilla Link 11985
Resolution FIXED
Resolved on Sep 12, 2012 17:06
Version 3.0
OS Linux
Attachments memcpy() test case
Reporter LLVM Bugzilla Contributor
CC @asl,@tkremenek,@darkbuck

Extended Description

When doing an optimized fixed-length memcpy() using a C source label as the origin, the code generator fails to take into account that %rip advances as the code executes. The result is that the same location is used for each mov into %[e|r]ax, rather than working through the entire origin area:

0x4005d9 <main()+9>: mov -0x34(%rip),%ax # 0x4005ac <testCase+44> 0x4005e0 <main()+16>: mov %ax,-0x2c(%rbp) 0x4005e4 <main()+20>: mov -0x3e(%rip),%eax # 0x4005ac <testCase+44> 0x4005ea <main()+26>: mov %eax,-0x30(%rbp) 0x4005ed <main()+29>: mov -0x48(%rip),%rax # 0x4005ac <testCase+44> 0x4005f4 <main()+36>: mov %rax,-0x38(%rbp) 0x4005f8 <main()+40>: mov %rax,-0x40(%rbp)

The failure occurs when building with clang using -O3.

llvmbot avatar Feb 12 '12 03:02 llvmbot

fixed in r163743.

darkbuck avatar Sep 13 '12 00:09 darkbuck

patch is submitted for review @ http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120827/149473.html

  • michael

darkbuck avatar Sep 06 '12 07:09 darkbuck

It's doing a memcpy from basicblock address: memcpy(buffer, (unsigned char*)&&nativeDebug, 22);

    movw    Ltmp0(%rip), %ax
    movw    %ax, 20(%rdi)
    movl    Ltmp0(%rip), %eax
    movl    %eax, 16(%rdi)
    movq    Ltmp0(%rip), %rax
    movq    %rax, 8(%rdi)
    movq    %rax, (%rdi)
    movl    $22, %eax
    ret

Ltmp0: ## Block address taken

The offsets got lost somewhere.

llvmbot avatar Feb 16 '12 01:02 llvmbot

cloned to rdar://problem/10869587

tkremenek avatar Feb 15 '12 21:02 tkremenek