[PATCH] D21620: [LV] Don't widen trivial induction variables

Matthew Simpson via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 13:32:32 PDT 2016


mssimpso created this revision.
mssimpso added reviewers: mkuper, sbaranga, jmolloy, nadav.
mssimpso added subscribers: llvm-commits, mcrosier.
Herald added a subscriber: mzolotukhin.

We currently always try to vectorize induction variables. However, if an induction variable is only used for counting loop iterations or computing addresses with getelementptr instructions, this doesn't really make sense. We only see a benefit from vectorizing induction variables if they are used in non-trivial ways. For example, here the induction variable is stored to memory:

```
for (int i = 0; i < n; ++i)
  a[i] = i;
```

Needlessly vectorizing causes us to generate unnecessary phi nodes, extracts, and other computation inside the loop. InstCombine can sometimes clean up the code we generate, but in general it cannot do so completely, especially when the unroll factor is greater than one (we create dependent step vectors that are difficult to simplify). It would be better if we didn't generate poor code to begin with.

This patch checks that induction variables are used in non-trivial ways before deciding to widen them. If an induction variable is only used for counting iterations or computing addresses, we scalarize it instead.

This change results in a static reduction in the number of instructions in nearly every benchmark in spec2000 and spec2006. In addition, we've observed significant performance improvements (> 1%) in several of them with no non-noise reductions. Experiments were conducted on Kryo.

Please take a look.

http://reviews.llvm.org/D21620

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/LoopVectorize/gep_with_bitcast.ll
  test/Transforms/LoopVectorize/induction.ll
  test/Transforms/LoopVectorize/iv_outside_user.ll
  test/Transforms/LoopVectorize/reverse_induction.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21620.61599.patch
Type: text/x-patch
Size: 16210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160622/553677f5/attachment.bin>


More information about the llvm-commits mailing list