[LLVMbugs] [Bug 6956] New: Array operations

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 27 14:25:19 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=6956

           Summary: Array operations
           Product: new-bugs
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: new-feature
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: bearophile at mailas.com
                CC: llvmbugs at cs.uiuc.edu


This is a low-priority enhancement request. Seeing how many things are done by
LLVM I am asking if it can be positive for LLVM to perform something already
done by D language front-end.

In all D1 and D2 language compilers there is native support array operations,
like:

c[] = a[] * b[];
c[] *= a[] * 20 + b[] * 6;

Where a, b, c are arrays of the same length, of a built-in type like int, real,
double, unsigned byte, etc.

Both dynamic arrays (allocated on the heap) and static arrays (allocated on the
stack, with a length known at compile-time) can be used with the same syntax.

In D static arrays are given to functions by value (unlike C language). (This
can be useful for very short arrays, that can be kept in SSE registers).

Currently such vector ops are performed by the D front-end, for example the LDC
compiler that uses LLVM as back-end. But such operations are currently not
efficient.

Currently some arrays ops are implemented with functions that contain
handwritten asm, for example relative to arrays of signed integers:
http://www.dsource.org/projects/phobos/browser/branches/phobos-1.x/phobos/internal/arrayint.d

Or arrays of doubles:
http://www.dsource.org/projects/phobos/browser/branches/phobos-1.x/phobos/internal/arraydouble.d?rev=811

While the other ones are translated to normal loops.

They are not efficient because they are always translated to a function call,
even when the product of two static arrays of 4 floats can be done with a
single SSE instruction.

This feature is not the same thing as loop vectorization, because there is no
need for LLVM to analyse loops and infer things, the front-end can just convert
the D vector ops to defined LLVM instructions (both in the dynamic and static
case. In the static case LLVM can produce better code).

Then LLVM can compile the ops well, using SSE or future wider AVX registers,
partially unrolling loops (even in the dynamic case), and eventually even
splitting the computation to different CPUs because each item in the array has
no dependences to other elements, it's a pure parallel loop.

Such vector ops can be useful for other languages and compilers too that use
LLVM as back-end (like valarray operator in C++).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list