Hi, I am hoping that someone can help me figure out how to prevent the insertion of "memcpy" from the assembly source. My target is an instruction set simulator that doesn't support this. Thank you for your valuable time. Wolf *Here are my compile commands:* $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o vl_matrix_float.ll $ llc vl_matrix_float.ll *IR File Snip:* %0 = bitcast [10 x [10 x float]]* %a to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([10 x [10 x float]]* @main.a to i8*), i32 400, i32 4, i1 false) %1 = bitcast [10 x [10 x float]]* %b to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* bitcast ([10 x [10 x float]]* @main.b to i8*), i32 400, i32 4, i1 false) store i32 0, i32* %sum, align 4 *Assembly File Snip:* # BB#0: # %entry lui $2, %hi(_gp_disp) addiu $2, $2, %lo(_gp_disp) addiu $sp, $sp, -1664 sw $ra, 1660($sp) # 4-byte Folded Spill sw $fp, 1656($sp) # 4-byte Folded Spill sw $17, 1652($sp) # 4-byte Folded Spill sw $16, 1648($sp) # 4-byte Folded Spill move $fp, $sp addu $17, $2, $25 lw $1, %got($main.a)($17) addiu $5, $1, %lo($main.a) lw $25, %call16(memcpy)($17) addiu $16, $fp, 1248 move $4, $16 addiu $6, $zero, 400 jalr $25 move $gp, $17 lw $1, %got($main.b)($17) addiu $5, $1, %lo($main.b) lw $25, %call16(memcpy)($17) addiu $17, $fp, 848 move $4, $17 jalr $25 addiu $6, $zero, 400 sw $zero, 820($fp) sw $zero, 844($fp) addiu $2, $fp, 420 b $BB0_2 addiu $3, $fp, 20 $BB0_1: -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/2da75a6d/attachment.html>
> On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hi, > > I am hoping that someone can help me figure out how to prevent the insertion of "memcpy" from the assembly source. > > My target is an instruction set simulator that doesn't support this. > > Thank you for your valuable time. > > Wolf > > Here are my compile commands: > $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o vl_matrix_float.llTechnically -fno-bultin prevents the compiler from understand the memset in the original code. The right option to prevent the compiler from insert libc calls “out-of-the-blue” is -ffreestanding. However I thought that right now clang does not differentiate these, so your result is somehow strange. Can you include the matrix_float.c source code? — Mehdi> $ llc vl_matrix_float.ll > > IR File Snip: > %0 = bitcast [10 x [10 x float]]* %a to i8* > call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([10 x [10 x float]]* @main.a to i8*), i32 400, i32 4, i1 false) > %1 = bitcast [10 x [10 x float]]* %b to i8* > call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* bitcast ([10 x [10 x float]]* @main.b to i8*), i32 400, i32 4, i1 false) > store i32 0, i32* %sum, align 4 > > Assembly File Snip: > > # BB#0: # %entry > lui $2, %hi(_gp_disp) > addiu $2, $2, %lo(_gp_disp) > addiu $sp, $sp, -1664 > sw $ra, 1660($sp) # 4-byte Folded Spill > sw $fp, 1656($sp) # 4-byte Folded Spill > sw $17, 1652($sp) # 4-byte Folded Spill > sw $16, 1648($sp) # 4-byte Folded Spill > move $fp, $sp > addu $17, $2, $25 > lw $1, %got($main.a)($17) > addiu $5, $1, %lo($main.a) > lw $25, %call16(memcpy)($17) > addiu $16, $fp, 1248 > move $4, $16 > addiu $6, $zero, 400 > jalr $25 > move $gp, $17 > lw $1, %got($main.b)($17) > addiu $5, $1, %lo($main.b) > lw $25, %call16(memcpy)($17) > addiu $17, $fp, 848 > move $4, $17 > jalr $25 > addiu $6, $zero, 400 > sw $zero, 820($fp) > sw $zero, 844($fp) > addiu $2, $fp, 420 > b $BB0_2 > addiu $3, $fp, 20 > $BB0_1: > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/2e909900/attachment.html>
On Sat, Oct 15, 2016 at 05:56:02PM -0500, Wolfgang McSneed via llvm-dev wrote:> I am hoping that someone can help me figure out how to prevent the > insertion of "memcpy" from the assembly source.Unless your backend explicitly always inlines memcpy, this is expected. In a lot of situation, creating a libcall for non-trivial sizes is far preferable than an inlined loop. Joerg
On Sat, Oct 15, 2016 at 04:01:36PM -0700, Mehdi Amini via llvm-dev wrote:> > > On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > > Hi, > > > > I am hoping that someone can help me figure out how to prevent the insertion of "memcpy" from the assembly source. > > > > My target is an instruction set simulator that doesn't support this. > > > > Thank you for your valuable time. > > > > Wolf > > > > Here are my compile commands: > > $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o vl_matrix_float.ll > > Technically -fno-bultin prevents the compiler from understand the > memset in the original code. The right option to prevent the compiler > from insert libc calls “out-of-the-blue” is -ffreestanding.Huh? The -fno-builtin is not the problem. The compiler is *expected* to call certain functions even for -ffreestanding. memcpy and memset are two of those. It is certainly perfectly valid target lowering for llvm.memcpy to be turned back into a libcall. Joerg