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

Copy Elision code produces incorrect code

Open igor-breger opened this issue 8 years ago • 2 comments

Bugzilla Link 37367
Version trunk
OS Linux
CC @topperc,@dwblaikie,@igor-breger,@rnk

igor-breger avatar May 08 '18 13:05 igor-breger

Calling conventions never cease to surprise me. Why would one violate such an assumption. =P Patches welcome, I do not have time to work on this in the near future.

rnk avatar May 08 '18 20:05 rnk

Copy Elision code produces incorrect code in some cases.

For example

llc -mtriple=i386-unknown < tmp.ll

define <4 x i8> @​test1(<4 x i8> %b) { %b.addr = alloca <4 x i8>, align 4 store <4 x i8> %b, <4 x i8>* %b.addr, align 4 %b.val = load <4 x i8>, <4 x i8>* %b.addr, align 4 ret <4 x i8> %b.val }

Generated code assume (incorrect) that the argument is packed in memory. movl 4(%esp), %eax movl 8(%esp), %ecx movl %ecx, (%eax) retl $4

For the reference

define <4 x i8> @​test2(<4 x i8> %b) { ret <4 x i8> %b }

movl 4(%esp), %eax movb 8(%esp), %cl movb 12(%esp), %dl movb 16(%esp), %ch movb 20(%esp), %dh movb %dh, 3(%eax) movb %ch, 2(%eax) movb %dl, 1(%eax) movb %cl, (%eax) retl $4

igor-breger avatar May 08 '18 14:05 igor-breger