LLVM 3.3 Vectorization Improvements

关于Loop Vectorization的二三事 关于Loop Vectorization的二三事 通过一些简单例子了解循环向量化 阅读详情

Tuesday, May 28, 2013

LLVM 3.3 Vectorization Improvements

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

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(%rdi,%rax,4), %xmm2
  paddd     %xmm2, %xmm1
  movdqu    (%rdi,%rax,4), %xmm2
  paddd     %xmm2, %xmm0
  addq      $8, %rax
  cmpq      %rax, %rcx
  jne       LBB0_4

Another important improvement is the support for loops that contain IFs, and the detection of the popular min/max patterns. LLVM is now able to vectorize the code below:

int fins_max(int *A, int n) {
  int mx = A[0];
  for (int i = 0; i < n; ++i)
    if (mx > A[i])
      mx = A[i];
  return mx;
}

In the last release, the loop vectorizer was able to vectorize many, but not all, loops that contained floating point arithmetic. Floating point operations are not associative due to the unique rounding rules. This means that the expression (a + b) + c is not always equal to a + (b + c). The compiler flag -ffast-math tells the compiler not to worry about rounding errors and to optimize for speed. One of the new features of the loop vectorizer is the vectorization of floating point calculations when -ffast-math mode is used. Users who decide to use the -ffast-math flag will notice that many more loops get vectorized with the upcoming 3.3 release of LLVM.

SLP Vectorizer

The SLP vectorizer (short for superword-level parallelism) is a new vectorization pass. Unlike the loop vectorizer, which vectorizes consecutive loop iterations, the SLP vectorizer combines similar independent instructions in a straight-line code.

void foo(int * restrict A, int * restrict B) {
  A[0] = 7+(B[0] * 11);
  A[1] = 6+(B[1] * 12);
  A[2] = 5+(B[2] * 13);
  A[3] = 4+(B[3] * 14);
}

The code above is compiled into the ARMv7s assembly sequence below. Notice that the 4 additions and 4 multiplication operations became a single Multiply-Accumulate instruction “vmla”.

_foo:
  adr       r2, LCPI0_0
  adr       r3, LCPI0_1
  vld1.32   {d18, d19}, [r1]
  vld1.64   {d16, d17}, [r3:128] 
  vld1.64   {d20, d21}, [r2:128]
  vmla.i32  q10, q9, q8            
  vst1.32   {d20, d21}, [r0]
  bx        lr
Command Line Flags

We’ve also added new command line flags to clang to control the vectorizers. The loop vectorizer is enabled by default for -O3, and it can be enabled or disabled for other optimization levels using the command line flags:

$ clang ... -fvectorize / -fno-vectorize   file.c

The SLP vectorizer is disabled by default, and it can be enabled using the command line flags:

$ clang ... -fslp-vectorize file.c

LLVM has a second basic block vectorization phase which is more compile-time intensive (BB vectorizer). This optimization can be enabled through clang using the command line flag:

$ clang ... -fslp-vectorize-aggressive file.c

We’ve made huge progress in improving vectorization during the development of LLVM 3.3. Special thanks to all of the people who contributed to this effort.

Posted by Nadav Rotem at 7:05 AM

Labels: new-in-llvm-3.3, optimization

编译器优化那些事儿(12):LLVM 自动向量化 背景向量化是一种将程序中标量代码转换为向量代码的优化手段。当前很多芯片架构都拥有向量计算单元,架构指令本身支持单指令多数据(SIMD)的并行计算,一条指令同时计算多个数据。使用向量化优化后,可以实现一个cycle计算多个标量数据,从而带来巨大的性能提升。在LLVM框架中有两个自动向量化pass:循环向量化(Loop Vectorizer)和 SLP向量化(Superword-level Paral... 阅读详情

相关推荐

编译优化之 - 向量化优化入门

1. 介绍 2. Intel高级向量扩展 3. GCC中向量化 4. ICC中向量化 5. AOCC/LLVM中向量化 1. 介绍 什么是自动向量化?   自动向量化(automatic vectorization)是自动并行化(automatic parallelization)的一种特殊情况,它将一次处理一对的标量运算转换为一次并行处理多对的向量运算。因此向量化可以显着加速一些带循环的...

zhugl的博客 1万+

LLVM, GCC, 自动向量化

这JB玩意 主要是为空不好判断吧,啥时候终止也不知道。4)缺点就是网页太老了,难道后面都不发展了吗?GCC这个网页还是有点意思。

xxxx的博客 425

LLVM Essentials-Packt 2016(读书笔记):TableGen讲解并不透彻,另外我还想知道后端优化步算法到底怎么编写?

LLVM Essentials 目录  [隐藏]  1 Playing with LLVM2 Building LLVM IR3 高级IR4 基本IR变换5 高级IR块变换6 IR到Selection DAG阶段7 为目标架构生成代码 Playing with LLVM[编辑] 寄存器变量(%var)、栈变量(alloca,%1

cteng的专栏 2897

Loop Vectorization: Diagnostics and Control

Loop Vectorization: Diagnostics and Control 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...

ronnie88597的博客 706

Arduino——GY39大气压、温湿度、光照模块

前几天买东西的时候买了一个GY39,这个模块集成了温湿度,大气压,海拔,光照一体,使用起来很方面。它有两种工作模式使用串口模式时需要搭配转接板,我选择了IIC模式,看一下通信协议吧,就是关于高八位和低八位的数据。看一下接线。

戚晨夕的博客 2605

医学图像分割实战:基于TransUNet训练自己的眼底硬渗出物数据集(附完整代码)

本文详细介绍了基于TransUNet的眼底硬渗出物分割实战指南,涵盖数据预处理、模型调优、训练策略及性能优化等关键环节。通过代码复现和实验对比,展示了TransUNet在医学图像分割中的优势,为糖尿病视网膜病变的早期诊断提供技术支持。

weixin_42524708的博客 362

New Loop Vectorizer

Friday, December 7, 2012 New Loop Vectorizer I would like to give a brief update regarding the development of the Loop Vectorizer. LLVM now has two vectorizers: The Loop Vectorizer, which operates o...

ronnie88597的博客 361

【题解-洛谷】B3644 【模板】拓扑排序 / 家谱树

有个人的家族很大,辈分关系很混乱,请你帮整理一下这种关系。给出每个人的后代的信息。输出一个序列,使得每个人的后辈都比那个人后列出。输出一个序列,使得每个人的后辈都比那个人后列出。如果有多种不同的序列,输出任意一种即可。),表示家族的人数。

写代码的犄角旮瘩 1065

llvm

1 LLVM Design &amp; Overview 31.1 LLVM Language Reference Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 User Guides 2452.1 Building LLVM with CMake . . . . . . . . . ...

qq_23484921的博客 494

【eclipse】win 10:eclipse 4.9 下载、安装和汉化(支持中英切换)

目录 一、eclipse下载 二、eclipse安装 三、eclipse在线汉化 四、eclipse离线汉化(推荐) 一、eclipse下载 ①官网下载地址(收费):https://www.eclipse.org/downloads/点击前往下载 ②【推荐】我的百度网盘下载地址(包括离线汉化包):点击下载 提取码:0nfw ③eclipse4.9其他地址下载:http...

顾三殇 —— 博客空间(软件测试) 1万+

逆向分析-SeparationPreview.aip-分色预览-结构分析(一)-x64dbg条件日志打印-命令表达式-PS脚本

从功能上分析,仅显示使用的专色这个功能,并没有触发插件接口。使用X64dbg加载illustrator进程,切换到句柄窗口,在窗口过程中,右键刷新获取界面。在x64dbg中,在UI中可以输入一些条件表达式,能够计算出对应的值,并打印在日志中。常用的,如果非暂停,输出第一个参数。参数二是utf16的指针,utf16@字符串地址,这里的字符串地址为[[ebp-108]]参数一是utf8的,utf8@字符串地址,这里的字符串地址为[ebp-28]从界面上分析,一个颜色列表,及仅显示专色的多选框组成。

插件开发 643

llvm循环向量化流程

llvm向量化流程(llvm版本9.0) 采用了最新的llvm版本,向量化流程如图所示: 解释后续在写:

格子衫爱上Helloworld 1559

AI应用架构师:用RAG解决大模型“幻觉”问题的客服架构设计

在当今的智能客服领域,大语言模型(LLM)凭借流畅的对话能力和强大的理解能力,逐渐取代传统规则式机器人,成为客服系统的核心。但随之而来的“幻觉”问题(即模型编造不存在的信息)却成了致命伤:比如客户问“你们的产品保修期多久”,AI客服可能会自信地回答“3年”,而实际保修期只有1年——这种错误不仅会误导客户,还可能引发投诉、退货甚至法律风险。

AI天才研究院 915

LLVM 3.3完全兼容C++11

作者Jeff Martin,译者臧秀涛发布于 七月 01, 2013 最近发布的LLVM 3.3带来了大量新特性,其中包括通过Clang子项目实现的完全兼容C++11的编译器。最重要的新特性是支持一些新的CPU架构,包括AArch64(64位ARM)、AMD的R600 GPU和IBM的z/Architecture(s390x),再就是改进了对MIPS和Powe...

weixin_30855761的博客 232

⭐️VMwareWorkstation17.0虚拟机搭建WindowsXP虚拟机(完整安装步骤详细图文教程)

Windows XP是微软公司研发的计算机操作系统,于2001年10月25日正式发布。其名字中“XP”的意思来自英文中的“体验”(Experience)。Windows XP使用了Luna图形用户界面和双列开始菜单,提升了系统的安全性和工作性能,提供了WiFi支持,简化了软件的安装和运行,并增加了远程桌面功能。

Python老吕的博客 1万+

用 CDS 作为 Referenced Data Source 开发 SAP Gateway OData 服务,一条更轻的 SEGW 路线

本文介绍了SAP Gateway项目中从传统手工建模到基于CDS View的现代化开发方式转变。主要内容包括: 传统方式需要在SEGW中手动创建Entity Type、Entity Set等元素,并在DPC_EXT中编写大量查询逻辑,存在模型层和业务逻辑重复表达的问题。 7.50版本后,SAP Gateway与ABAP CDS深度集成,可通过SEGW直接引用CDS View作为数据源,自动生成数据模型和SADL读取逻辑,支持完整的OData查询功能。 最佳实践建议通过Consumption View而非直接

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 703

向量化(Vectorization)

向量化(Vectorization)   向量化是非常基础的去除代码中for循环的艺术,在深度学习安全领域、深度学习实践中,你会经常发现自己训练大数据集,因为深度学习算法处理大数据集效果很棒,所以你的代码运行速度非常重要,否则如果在大数据集上,你的代码可能花费很长时间去运行,你将要等待非常长的时间去得到结果。所以在深度学习领域,运行向量化是一个关键的技巧。 下面举一个例子: import nump...

一只攻城狮的博客 7641

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

LLVM的分析和转换Passes

LLVM的分析和转换Passes1 简介2 分析Passes2.1 -aa-eval:详细的别名分析精确评估2.2 -basicaa:基本别名分析(无状态别名分析实现)2.3 -basiccg:基本的CallGraph结构2.4 -count-aa:统计别名分析查询响应2.5 -da:依赖关系分析2.6 -debug-AA:使用debugger的别名分析2.7 -domfrontier:支配边界构...

梦在哪里的博客 5602

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

LLVM编译流程详解

LLVM 什么是LLVM? LLVM项目是一系列分模块、可重用的编译工具链。它提供了一种代码编写良好的中间表示(IR),可以作为多种语言的后端,还可以提供与变成语言无关的优化和针对多种cpu的代码生成功能。 传统编译器分为三个阶段:前端—>优化器—>后端 LLVM也分为三个阶段,但是设计上有区别,LLVM不同的就是对于不同的语言他都提供了同一种中间表示: 前端可以使用不同的编译工具对代码文件做词法分析以形成抽象语法树AST,然后将分析好的代码转换成LLVM的中间表示..

就是这个七昂的博客 1万+

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 237

选型笔记:Type‑C 扩展坞方案评估|DP1.4 转 HDMI2.0 桥接芯片 GSV2201S@ACP

本文记录 GSV2201S 这款 DP1.4a 转 HDMI2.0 桥接芯片评估,梳理视频、HDCP、PD 集成能力,总结 Type‑C 转接 Dongle、扩展坞方案的适配边界,以及差分走线、PD 时序、HDCP 握手等高频调试问题,为 C 口视频转接方案选型提供参考。

ACP广源盛的博客 220

C++移动构造函数详解

移动构造函数是C++11引入的一种特殊构造函数,用于从临时对象(右值)"窃取"资源来初始化新对象,而不是进行昂贵的深拷贝。char* data;public:// 移动构造函数:参数是右值引用 &&// 关键:把源对象的资源置空。

拒绝AI文,努力在AI时代写出感动人心的好文章 389

ThunderKittens 深度解析:一个不基于 MLIR 的 C++ 模板 GPU DSL

Triton 是"让更多人能写 GPU kernel",ThunderKittens 是"让会写的人写得更爽"。前者用 MLIR 换易用性,后者用 C++ 模板换可控性。它们不是替代关系,而是覆盖了 GPU 编程光谱的两端。ThunderKittens 的出现,本质上是对"GPU DSL 必须基于 MLIR"这一默认假设的挑战。编译期类型系统本身就可以是一个强大的 DSL 基础设施,不需要中间 IR,不需要黑盒 pass,也能实现 tile 级抽象和零运行时开销。

Maxwell_Newton的博客 334

C++ 多态详解:作用、原理与实战用法

多态是C++面向对象的核心特性,通过虚函数实现运行期动态绑定,使同一接口在不同对象上表现出不同行为。其核心作用包括统一接口、提升可扩展性、降低耦合、支持运行时分派与批量处理。实现依赖虚函数表(vtable)和虚指针(vptr),需注意虚析构函数、对象切片等陷阱。相比编译期多态(模板),运行期多态灵活性高但有调用开销。合理结合两者,可兼顾代码的灵活性与性能,是构建可扩展、低耦合系统的关键。

2402_85743155的博客 377

【C语言】字符与字符串函数

C语言中字符串为以\0结尾的字符数组,标准库函数基于此约定。本文解析字符串内存布局,详解ctype.h与string.h中字符分类、长度计算、拷贝、比较等函数的使用要点,强调长度判断与越界风险,最后通过命令行待办事项示例整合fgets、sscanf、strncpy、strcmp,展示实际应用中的关键细节。

记录在学习过程中学到的知识 343
上一篇: LLVM 3.3 Released!
下一篇: LLVM Debian/Ubuntu nightly packages
「已注销」
博客等级 码龄11年 2粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值