[llvm] r176399 - PR14448 - prevent the loop vectorizer from vectorizing the same loop twice.

Hal Finkel hfinkel at anl.gov
Tue Mar 5 11:01:00 PST 2013


----- Original Message -----
> From: "Andrew Trick" <atrick at apple.com>
> To: "Nadav Rotem" <nrotem at apple.com>
> Cc: "Commit Messages and Patches for LLVM" <llvm-commits at cs.uiuc.edu>
> Sent: Tuesday, March 5, 2013 12:42:34 PM
> Subject: Re: [llvm] r176399 - PR14448 - prevent the loop vectorizer from	vectorizing the same loop twice.
> 
> 
> 
> 
> On Mar 3, 2013, at 12:17 AM, Nadav Rotem < nrotem at apple.com > wrote:
> 
> 
> 
> 
> Hi Chandler,
> 
> 
> 
> Maybe I did not explain the problem well. After vectorization we get
> this loop structure:
> 
> 
> [VECTOR LOOP]
> | 
> v
> [SCALAR POST LOOP]
> 
> 
> The scalar post loop executes the last few iterations, or the entire
> loop if the runtime checks fail. The scalar loop is still
> vectorizable, because it is the original loop.
> 
> 
> After running the loop vectorizer again we will get this structure:
> 
> 
> [VECTOR LOOP]
> | 
> v
> [VECTOR LOOP II]
> | 
> v
> [SACLAR LOOP]
> 
> 
> The second vector loop is dead code because it has all of the runtime
> checks as the first loop. The program is still correct.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> The very premise of metadata is that removing it is the safe
> alternative,
> 
> 
> Yes, and removing the metadata will not change the correctness of the
> code, just generate larger code.
> 
> 
> 
> 
> 
> 
> 
> and you've designed this in such a way that removing metadata is
> exactly the thing which other optimizations cannot do.
> 
> 
> No. If other optimizations remove the metadata then the scalar loop
> will be re-vectorized, and the bypass loop will skip the second
> vector loop. This is still correct but suboptimal because it will
> generate larger code.
> 
> 
> 
> 
> 
> 
> 
> Why isn't the solution to "The LoopVectorizer often runs multiple
> times on the same function due to inlining" simply to not include
> the loop vectorizer in the CGSCC pass manager that has this
> behavior, and instead run it in a late stage of the pass manager,
> once for each function?
> 
> 
> Yes. At the moment we run all of our passes in a single pass manager,
> and until we split the pass manager to two phases (canonicalization
> + lowering) we are going to have this problem. We are working on a
> solution to this problem, but it will take some time.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Fundamentally, there seem to be two options for how to design the
> loop vectorizer:
> 
> 
> 
> 
> LTDR: This workaround is needed to prevent code bloat. We plan to
> split the pass manager in the near future.
> 
> Yes, hopefully reorganizing the passes will solve this eventually.
> Just for the sake of discussion, another option is inserting branch
> probability metadata on the scalar loop backedge indicating that it
> iterates an expected vector-width/2 times. And teach the vectorizer
> to skip low trip count loops.

FWIW, I like this idea. Nevertheless, having 'nosimd' metadata could also be useful. For example, xlC provides a '#pragma nosimd' and it might be worthwhile supporting something similar. Luckily, I think that we can (and perhaps should) have both.

 -Hal

> 
> 
> -Andy
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list