# Loop Vectorization: Diagnostics and Control

DevFeed: [Loop Vectorization: Diagnostics and Control](<https://devfeed.tech/articles/loop-vectorization-diagnostics-and-control-42945.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2014/11/loop-vectorization-diagnostics-and.html>)

Author: Tyler Nowicki

Published: 2014-11-24T15:12:00Z

Content type: article

Language: en

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

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [clang](<https://devfeed.tech/topics/clang.md>), [C](<https://devfeed.tech/topics/c.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Hardware](<https://devfeed.tech/topics/hardware.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [diagnostics](<https://devfeed.tech/tags/diagnostics.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [loop-vectorizer](<https://devfeed.tech/tags/loop-vectorizer.md>), [loops](<https://devfeed.tech/tags/loops.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [vectorization](<https://devfeed.tech/tags/vectorization.md>)

## AI overview

This article explains LLVM loop-vectorization diagnostics and controls. It covers diagnostic remarks, command-line options, and pragma syntax for tuning vectorization, interleaving, and unrolling, including examples of vectorized and non-vectorized C loops.

## Source excerpt

Loop vectorization was first introduced in LLVM 3.2 and turned on by default in LLVM 3.3. It has been discussed previously on this blog in 2012 and 2013, as well as at FOSDEM 2014, and at Apple's WWDC 2013. The LLVM loop vectorizer combines multiple iterations of a loop to improve performance. Modern processors can exploit the independence of the interleaved instructions using advanced hardware features, such as multiple execution units and out-of-order execution, to improve performance. Unfortunately, when loop vectorization is not possible or profitable the loop is silently skipped. This is a problem for many applications that rely on the performance vectorization provides. Recent updates to LLVM provide command line arguments to help diagnose vectorization issues and new a pragma syntax for tuning loop vectorization, interleaving, and unrolling. New Feature: Diagnostics Remarks Diagnostic remarks provide the user with an insight into the behavior of the behavior of LLVM's optimization passes including unrolling, interleaving, and vectorization. They are enabled using the Rpass command line arguments. Interleaving and vectorization diagnostic remarks are produced by specifying the 'loop-vectorize' pass. For example, specifying '-Rpass=loop-vectorize' tells us the following loop was vectorized by 4 and interleaved by 2. void test1(int *List, int Length) { int i = 0; while(i < Length) { List[i] = i*2; i++; } } clang -O3 -Rpass=loop-vectorize -S test1.c -o /dev/null test1.c:4:5: remark: vectorized loop (vectorization factor: 4, unrolling interleave factor: 2) while(i < Length) { ^ Many loops cannot be vectorized including loops with complicated control flow, unvectorizable types, and unvectorizable calls. For example, to prove it is safe to vectorize the following loop we must prove that array 'A' is not an alias of array 'B'. However, the bounds of array 'A' cannot be identified. void test2(int *A, int *B, int Length) { for (int i = 0; i < Length; i++) A[B[i]]++; }