<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 23, 2013 at 8:51 PM, huyanlin19870324 <span dir="ltr"><<a href="mailto:huyanlin19870324@126.com" target="_blank">huyanlin19870324@126.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial"><div>SROA optimization pass did some optimizations and transforms for memcpy function,such as ld/st operations.When someone has written down code like size>sizeof(dest) in memcpy(*dest,*src,size),<br>
</div></div></blockquote><div><br></div><div>How could it be valid to memcpy when the size of the destination is smaller than the number of bytes you asked to copy? It looks to me like your program has undefined behavior. Don't do that.<br>
<br>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial"><div>there was much likely a wrong code generation.for example,considered as such testcase:<br>
int main()<br>{<br> char ch;<br> short sh = 0x1234;<br> memcpy(&ch,&sh,2);<br> printf("ch=0x%02x\n",ch);<br>}<br>At i586 target,the corect executive result was "ch=0x34",but once openning the SROA optimization </div>
<div>pass it turned out as "ch=0x00".<br> Then I had a try to dump IR code for comparsion between before and after SROA optimization pass.<br>IR before SROA:<br>define i32 @main() #0 {<br>entry:<br> %retval = alloca i32,align 4,<br>
%ch = alloca i8,align 1,<br> %sh = alloca i16,align 2,<br> store i32 0,i32* %retval,<br> store i16 4660,i16* %sh,align 2,!tbaa!0,<br> %0 = bitcast i16* %sh to i8*<br> call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ch,i8* %0,,i32 2,i32 1,i1 false),<br>
%1 = load i8* ch,align 1,!tbaa!0,<br> %conv = sext i8 %1 to i32,<br> %call = call i32 (i8*,...)* @printf(i8* getelementptr inbounds([9*i8]*@.str,i32 0,i32 0),i32 %conv),<br> ret i32 0,<br>}</div>
<div>IR after SROA:<br>define i32 @main() #0 {<br>entry:<br> %conv = sext i8 undef to i32,<br> %call = call i32 (i8*,...)* @printf(i8* getelementptr inbounds([9*i8]*@.str,i32 0,i32 0),i32 %conv),<br> ret i32 0,<br>}</div>
<div> Then I tried to debbuging with SROA.cpp,I found in funcction visitMemTransferInst,it accorded the IR instruction "call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ch,i8* %0,,i32 2,i32 1,i1 false)",would produce such codes(finally,memcpy disappeared and the codes would be delated,IR after SROA become incorrect ,am i right?)<br>
%sh.0.cast = bitcast i8* ch to i16*,<br>%sh.0.copyload = load i16* sh,align 1,<br>store i16 %sh.0.copyload,i16* %sh.0.cast,align 1,</div>
<div> </div>
<div> In a word,I think visitMemTransferInst function in SROA.cpp had maken a incorrect optimization for memcpy in the situation like memcpy's size>sizeof(dest).<br>am i write? I would appreciate any suggestions on this.Thanks very much!<br>
</div></div><br><br><span title="neteasefooter"><span></span></span><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>