[PATCH] D117982: [Doc][RFC][SLP] Add more description for SLP Vectorizer

Yueh-Ting Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 23 04:10:42 PST 2022


eopXD created this revision.
eopXD added reviewers: Ayal, reames.
Herald added subscribers: luke957, s.egerton, simoncook.
eopXD requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The SLP vectorizer section have seldom description. This patch tries
to add more to it. I am not an expert in vectorization, I am just pointing out
what I currently know about the SLP Vectorizer and how you may begin if you
came across the SLP pass. So this is an RFC and comments are welcomed!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117982

Files:
  llvm/docs/Vectorizers.rst
  llvm/docs/slp-tree.png


Index: llvm/docs/Vectorizers.rst
===================================================================
--- llvm/docs/Vectorizers.rst
+++ llvm/docs/Vectorizers.rst
@@ -443,7 +443,25 @@
     A[3] = a2*(a2 + b2);
   }
 
-The SLP-vectorizer processes the code bottom-up, across basic blocks, in search of scalars to combine.
+The SLP idea is originated from S. Larsen and S. Amarasinghe [1]_. The
+original idea of SLP is to capture chances of parallelism within a basic block,
+that is, without regard to the loop context. It's simple and robust idea is why
+the optimization is applicable to production compilers. The SLP idea is later
+implemented into GCC [2]_ . There is a report about the GCC's implementation
+[3]_ that summarizes the implement methods and possible future work for
+building a SLP Vectorizer.
+
+The LLVM implements SLP vectorization based on the GCC report [3]_, where the
+compiler builds up "computation tree" from bottom-up. The tree starts from
+collecting store and GEP instructions, group them into "bundles", then expand
+when operands of the bundled can be further grouped into more bundles.
+
+By opening the option ``view-slp-tree``, you can get a Graphviz visualization
+of the tree built. The computation tree will look like the picture below.
+"Isomorphic" statements (statements with the same computation) are grouped
+together.
+
+.. image:: slp-tree.png
 
 Usage
 ------
@@ -454,3 +472,23 @@
 .. code-block:: console
 
    $ clang -fno-slp-vectorize file.c
+
+You can investigate more on how the SLP Vectorizer works by feeding LLVM IR to
+it. Note that you will need to specify a target with vector register to the
+compiler (e.g. for RISCV, you will need to include the ``V`` or ``Zve``
+extension). Invoke the SLP Vectorizer pass with the following command:
+
+.. code-block:: console
+
+   $ clang --passes="slp-vectorizer" -mtriple=riscv64 -mattr=+v -S file.ll
+
+References
+----------
+.. [1] "Exploiting superword level parallelism with multimedia instruction
+    sets", S. Larsen, S. Amarasinghe, ACM SIGPLAN 2000.
+
+.. [2] "Auto-vectorization in GCC" [`link
+    <https://gcc.gnu.org/projects/tree-ssa/vectorization.html>`]
+
+.. [3] "Loop-aware SLP in GCC", by I. Rosen, D. Nuzman, A.l Zaks,
+    GCC Developer's Summit 2007.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117982.402312.patch
Type: text/x-patch
Size: 2274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220123/323a2bc3/attachment.bin>


More information about the llvm-commits mailing list