[llvm-dev] array fill idioms

Ryan Taylor via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 10 14:07:46 PST 2016


Like a list initializer, but will do partials/slices?

Are you just looking to create an intrinsic that will generate a jump to a
lib routine?

On Thu, Nov 10, 2016 at 5:02 PM, Bagel via llvm-dev <llvm-dev at lists.llvm.org
> wrote:

> Yes, I know this works peachy keen for char arrays.  I'm looking at (which
> is
> hard to express in C) something like
>
> void foo () {
>    int bar[20] = { 42, 42, ..., 42 };
> }
>
> I don't want to do a memcopy of the 20 element constant array, and memset
> doesn't work here.  I want an intrinsic that copys the scalar int constant
> 42
> to each element of the int array.
>
> bagel
>
>
> On 11/10/2016 03:30 PM, Mehdi Amini wrote:
> > Hi,
> >
> > An alternative is to perform what is done for the equivalent C construct:
> >
> > void foo() {
> >   char bar[20] = “hello”;
> > }
> >
> > ->
> >
> > @foo.bar = private unnamed_addr constant [20 x i8]
> c"hello\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", align 16
> > define void @foo() #0 {
> >   %1 = alloca [20 x i8], align 16
> >   %2 = bitcast [20 x i8]* %1 to i8*
> >   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* getelementptr
> inbounds ([20 x i8], [20 x i8]* @foo.bar, i32 0, i32 0), i64 20, i32 16, i1
> false)
> >   ret void
> > }
> >
> >
> > —
> > Mehdi
>
> _______________________________________________
> 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/20161110/c9aa075d/attachment.html>


More information about the llvm-dev mailing list