[LLVMdev] LLVM Loop Vectorizer puzzle

Hal Finkel hfinkel at anl.gov
Thu May 23 06:06:27 PDT 2013


----- Original Message -----
> 
> 
> 
> Hi,
> 
> Just from personal interest, is there a canonical way in IR+metadata
> to express "This small constant trip-count loop is desired to be
> converted into a sequence of vector operations directly"? Ie,
> mapping a 4 element i32 loop into a linear sequence of <4 x i32>
> operations. Obviously this may not always be a win, but I'm just
> wondering if there's a way to communicate this intent and get around
> the vectorizer-min-trip-count in specially desired cases, or if I
> should decide to generate vectorized IR directly. (This is in code
> coming from a DSL which will impliciltly insert annotations, not
> manually written loops.)
> 

I think that the answer is: not currently. On the other hand, if the loop is small enough to get unrolled, then you can either use the BB vectorization pass or the SLP vectorization pass to vectorize it.

 -Hal

> Cheers,
> Dave
> 
> 
> 
> 
> 
> On Thu, May 23, 2013 at 5:06 AM, Arnold Schwaighofer <
> aschwaighofer at apple.com > wrote:
> 
> 
> Hi,
> 
> The TinyTripCountVectorThreshold only applies to loops with a known
> (constant) trip count. If a loop has a trip count below this value
> we don’t attempt to vectorize the loop. The loop below has an
> unknown trip count.
> 
> Once we decide to vectorize a loop, we emit code to check whether we
> can execute one iteration of the vectorized body. This is the code
> quoted below.
> 
> 
> 
> On May 22, 2013, at 10:23 PM, maxs < xtxwy.ustc at gmail.com > wrote:
> 
> > Hi,
> > I have the llvm loop vectorizer to complie the following sample:
> > //=================
> > int test(int *a, int n) {
> > 
> > for(int i = 0; i < n; i++) {
> > 
> > a[i] += i;
> > 
> > }
> > 
> > 
> > return 0;
> > 
> > }
> > 
> > //================
> > The corresponded .ll file has a loop preheader:
> > //================
> > 
> > for.body.lr.ph : ; preds = %entry
> > %cnt.cast = zext i32 %n to i64
> > %0 = and i32 %n, 7
> > %n.mod.vf = zext i32 %0 to i64
> > %n.vec = sub i64 %cnt.cast, %n.mod.vf
> > %cmp.zero = icmp eq i32 %0, %n
> > br i1 %cmp.zero, label %middle.block, label %vector.body
> > //================
> > 
> > That is , if n <=7, the program will skip the vector.body. In
> > LoopVectorize.cpp , I see the following code:
> > //================
> > 
> > static cl::opt<unsigned>
> > TinyTripCountVectorThreshold("vectorizer-min-trip-count",
> > cl::init(16), ... );
> > //================
> > 
> > The minimal loop count is 16. What is the "n<=7" meaning? Thanks.
> > 
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 
> 
> --
> 
> cheers, dave tweed__________________________
> high-performance computing and machine vision expert:
> david.tweed at gmail.com
> "while having code so boring anyone can maintain it, use Python." --
> attempted insult seen on slashdot
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 




More information about the llvm-dev mailing list