# LLVM 3.3 Vectorization Improvements

DevFeed: [LLVM 3.3 Vectorization Improvements](<https://devfeed.tech/articles/llvm-3-3-vectorization-improvements-42883.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2013/05/llvm-33-vectorization-improvements.html>)

Author: Nadav Rotem

Published: 2013-05-28T07:05:00Z

Content type: release

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [clang](<https://devfeed.tech/topics/clang.md>), [x86](<https://devfeed.tech/topics/x86.md>), [Arm](<https://devfeed.tech/topics/arm.md>), [Code](<https://devfeed.tech/topics/code.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Parallelism](<https://devfeed.tech/topics/parallelism.md>)

Tags: [arm](<https://devfeed.tech/tags/arm.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [new-in-llvm-3-3](<https://devfeed.tech/tags/new-in-llvm-3-3.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [parallel](<https://devfeed.tech/tags/parallel.md>), [performance](<https://devfeed.tech/tags/performance.md>), [release](<https://devfeed.tech/tags/release.md>), [vectorization](<https://devfeed.tech/tags/vectorization.md>), [x86](<https://devfeed.tech/tags/x86.md>)

## AI overview

An update on LLVM 3.3's vectorization improvements, including a loop vectorizer enabled by default at -O3, a new SLP vectorizer, new Clang command-line flags, improved x86 and Arm cost models, loop unrolling, and support for additional loop patterns.

## Source excerpt

I would like to give a brief update regarding vectorization in LLVM. When LLVM 3.2 was released, it featured a new experimental loop vectorizer that was disabled by default. Since LLVM 3.2 was released, we have continued to work hard on improving vectorization, and we have some news to share. First, the loop vectorizer has new features and is now enabled by default on -O3. Second, we have a new SLP vectorizer. And finally, we have new clang command line flags to control the vectorizers. Loop Vectorizer The LLVM Loop Vectorizer has a number of new features that allow it to vectorize even more complex loops with better performance. One area that we focused on is the vectorization "cost model". When LLVM estimates if a loop may benefit from vectorization it uses a detailed description of the processor that can estimate the cost of various instructions. We improved both the X86 and ARM cost models. Improving the cost models helped the compiler to detect benefitting loops and improve the performance of many programs. During the analysis of vectorized programs, we also found and optimized many vector code sequences. Another important improvement to the loop vectorizer is the ability to unroll during vectorization. When the compiler unrolls loops it generates more independent instructions that modern out-of-order processors can execute in parallel. The loop below adds all of the numbers in the array. When compiling this loop, LLVM creates two independent chains of calculations that can be executed in parallel. int sum_elements(int *A, int n) { int sum = 0; for (int i = 0; i < n; ++i) sum += A[i]; return sum; } The innermost loop of the program above is compiled into the X86 assembly sequence below, which processes 8 elements at once, in two parallel chains of computations. The vector registers XMM0 and XMM1 are used to store the partial sum of different parts of the array. This allows the processor to load two values and add two values simultaneously. LBB0_4: movdqu 16(%rd