<div style="line-height:1.7;color:#000000;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>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 id="netease_mail_footer"></span></span>