Introduction to load elimination in the GVN pass

llvm pass系列 在LLVM中,一致性分析框架并不是一个特定的、官方命名的组件,但我们可以理解为在LLVM的架构和工具集中,存在一系列用于确保代码转换和优化过程中一致性的机制和方法。可能除了ir和pass之外,对编译器语义不变这个核心的理论,也值得参考学习,面试的时候最多也就问你知道哪些pass,几乎不会问这些问题,但是这是编译器原理,是编译器的目标约束。它们基于分析pass提供的信息,对程序进行实际的转换和优化操作。LLVM的pass架构使得相同的优化和分析可以在不同的目标架构和操作系统上运行,提高了代码的跨平台兼容性。 阅读详情

Thursday, December 17, 2009

Introduction to load elimination in the GVN pass

One very important optimization that the GVN pass (opt -gvn) does is load elimination. Load elimination involves several subsystems (including alias analysis, memory dependence analysis, SSA construction, PHI translation) and has many facets (full vs partial redundancy elimination, value coercion, handling memset/memcpy, etc). In this post, I introduce and motivate the topic, which will let us expand on it in future posts.

Basic Redundant Load Elimination

GVN (which stands for “Global Value Numbering”, though this detail has nothing to do with load elimination) is responsible for the form of load elimination known as redundant load elimination. This is the elimination of loads whose values are already available (other forms of load elimination includes deletion of dead loads). A simple example of a redundant load is:

  %x = load i32* %P
  %y = load i32* %P  ; <- Redundant

Clearly in this example, we can delete the second load and “replace all uses” of %y with %x, because the value at address %p is already available as the value “i32 %x”. Another simple form of redundant elimination comes about from stores, as in:

  store i32 4, i32* %P
  %a = load i32* %P

In this example, we can replace %a with 4. This sort of transformation generalizes to support other operations: the GVN pass can forward memsets to loads, memcpy from constant globals to loads, etc. Note that GVN is not allowed to optimize away volatile loads.

The implementation of this is pretty straight-forward: GVN (through the memdep class) scans backwards from the load that we are trying to eliminate up through the block until it gets an instruction that provides the value (as in these examples) or until it finds an instruction that might affect the memory in an unknown way like a call. If we find an instruction that potentially clobbers the memory location, we can’t eliminate the load.

However, straight-line code is pretty boring, lets look at more complex examples.

SSA Construction in GVN

GVN can also eliminate non-local loads, which can require PHI node insertion. Here’s a simple example:

BB1:
  store i32 5, i32* %P
  br label %Merge

BB2:
  %X = load i32* %P
   ... use %X ...
   br label %Merge

Merge:
  %Y = load i32 *%P
  ...
  ... use %Y ...

In this case, GVN scans for available values of %P within the block (starting at the %Y load), and runs into the top of the %Merge block. Since it got to the top of the block, it starts scanning the predecessor blocks (%BB1 and %BB2) and it finds out that the value of the load is 5 in BB1 and %X in BB2. GVN then renames these values with the SSAUpdater class, producing:

BB1:
  store i32 5, i32* %P
  br label %Merge

BB2:
  %X = load i32* %P
  ... use %X ...
  br label %Merge

Merge:
  %Y = phi i32 [5, %BB1], [%X, %BB2]
  ...
  ... use %Y ...

Replacing a load with a PHI node may not seem like a win, however the cost model we use in the LLVM optimizer assumes that PHI nodes will be coalesced away by the code generator, and are thus free. The logic that does PHI insertion is contained and maintained by the SSAUpdater class, which may be the subject of a future Blog post.

Pros and Cons of Redundant Load Elimination

We always consider it profitable to eliminate a load in the optimizer when possible. Loads can be quite expensive (e.g. if they miss in the cache), and load/store traffic can hide other redundant or further simplifyable logic from the scalar optimizer. One idiom used to test alias analyses usually looks like this:

  %A = load i32* %P
  store i32 1, i32* %Q
  %B = load i32* %P

  %C = sub i32 %A, %B
  ret i32 %C

If GVN + instcombine are able to turn this into “ret i32 0” then we know that alias analysis was able to prove that P and Q did not alias. While somewhat unlikely in the real world, this is one example that shows a scalar optimization (X-X == 0) that can not be done unless the redundant loads are eliminated.

The cost of eliminating redundant loads is that it creates longer live ranges that the code generator may not be able to cope with. This is a real issue that we don’t currently have a good solution for. The ultimate answer is that improved rematerialization will be able to rematerialize the load further down in the code to reduce register pressure, we don’t have great support for this yet though.

LLVM数据流分析的理论 LLVM数据流分析的理论 标量优化(scalar目录): 死代码消除(BDCE.cpp[code],ADCE.cpp[code],DCE.cpp[code]), 全局值编号(GVN.cpp[code]), 代码提升(ConstantHoisting.cpp[code]), 公共子表达式消除(EarlyCSE.cpp[code]), 代码下沉(Sink.cpp[code]), 以及各种循环优化等 过程间优化(IPO目录):无效参数消除(DeadArgumentElimination.cpp[code]) , 阅读详情

相关推荐

DSP28335新手避坑指南:手把手教你用CCS6.2生成10KHz SPWM(附完整工程)

本文详细介绍了如何使用DSP28335开发板和CCS6.2环境生成10KHz SPWM波形的完整工程指南。从开发环境配置、ePWM模块设置到SPWM算法实现,特别针对新手常见问题提供了解决方案和调试技巧,帮助工程师快速掌握DSP28335的SPWM生成技术。

weixin_42522374的博客 184

LLVM 编译器学习笔记之六十五 -- GVN(global value number)

1、实现方法:GVN算法及LLVM中的实现 - 薛奇星 - 20210217 - PLCT实验室_哔哩哔哩_bilibili

~ 飞 扬 的 天 空 ~ 1850

STM32CubeMX最新版下载安装全攻略(附官网访问问题解决方案)

本文提供了STM32CubeMX最新版的详细下载与安装指南,并针对国内开发者常见的官网访问缓慢、注册验证邮件延迟等问题,给出了实用的解决方案和备选策略。通过清晰的步骤解析,帮助用户快速部署这一强大的STM32图形化配置工具,从而高效启动嵌入式开发项目。

weixin_28256233的博客 200

Elimination

完全背包的题目,代码实现并不难,但是要理解题意,英语是硬伤~ 题意(人工翻译): 赢得其中一场淘汰赛的选手将会入围2214年的"Russian Code Cup"比赛 淘汰赛的赛制分为初赛和复赛,每场初赛都有c道问题,初赛的获胜者是排名前n位的选手,每场复赛的都有d道题目,复赛的获胜者只有一名,另外,在过去的决赛获胜的k名选手直接被邀请参加决赛而不用淘汰赛 在所有的的淘汰赛结束之后应该有不

smoggyxhdz的博客 638

企业多部门网络隔离实战:用华为交换机VLAN+Trunk实现行政/技术部安全隔离

本文详细介绍了如何利用华为交换机的VLAN划分与Trunk链路技术,实现企业行政与技术部门间的网络逻辑隔离。通过具体的配置案例,阐述了Access与Trunk端口的工作原理、单交换机与多交换机环境下的部署策略,并延伸至三层网关部署与ACL访问控制,为企业构建安全、高效的核心网络提供实战指导。

p4q5r6s7t的博客 582

AXI4接口说明

ACLK:全局AXI接口时钟输入(建议与系统时钟保持一致)ARESET_n:全局AXI接口复位信号,低电平有效。PS:在HBM AXI接口应用中,此复位端口仅应在数据传输开始前使用。若在传输开始后使用,会导致AXI接口与内存控制器失步(out-of-sync)。当开关启用时,IP核会将所有ARESET_n引脚内部连接在一起——因为内存作为一个整体工作。

rhtul的博客 1525

LVN和SVN算法在LLVM中的实现?

为了更深入地了解LLVM中LVN和SVN的实现,建议直接查看LLVM的源代码,特别是与GVN相关的部分,以及可能的自定义优化Pass。然而,可以推断出LLVM中的LVN实现可能通过限制GVN的作用域来模拟,而SVN则可能需要自定义优化Pass来实现。LLVM的LVN实现可能隐藏在GVN或类似的优化Pass中,因为LLVM的官方文档和源代码主要强调GVN,它作用于整个控制流图(CFG),但在某些情况下,可以通过限制其作用域来模拟LVN的效果。

怀揣梦想,一颗执着于技术的心从未磨灭,内心住着一颗顽强的小强时刻提醒自己层层突破自我,同时也成就他人 515

windchill安装搭建(保姆式)

保姆式搭建windchill 材料准备 Vmware工具,用来创建和打开虚拟机的工具 安装系统的镜像文件 数据库安装文件,这里是Oracle数据库 Windchill的安装包 Vmware工具,用来安装和打开虚拟机的软件 Windowsserver2008的镜像工具,用来安装虚拟机环境的系统,如果你有win2007或win2010的也可以,在做虚拟机时,需要先安装系统。 Oracle数据库安装包 Windchill11M030的安装包 (安装包如有需要可以私信邮箱发送) 虚拟机安装 安装虚拟机VMware

tr1294937662的博客 6225

CodeForces - 417A Elimination (完全背包)

题目链接:http://codeforces.com/problemset/problem/417/A点击打开链接 A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input output stand

xuejye的博客 512

Lumerical 教程,包含作者个人理解及相关设计案例 (目前共计184篇,持续更新中)

4138。

u011699626的博客 1657

VHDL语法学习笔记:一文掌握VHDL语法

今天给大侠带来FPGA 之 VHDL 语法学习笔记,话不多说,上货。 VHDL语法学习笔记 一、VHDL简介 1.1 VHDL 的历史 VHDL 的 英 文 全 名 是 Very-High-Speed Integrated Circuit Hardware DescriptionLanguage,诞生于 1982 年。 1987 年底,VHDL 被 IEEE 和美国国防部确认为标准硬件描述语言。自 IEEE 公布了 VHDL 的标准版本 IEEE-1076(简称 87 版)...

2万+

LLVM编译流程详解

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

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

5、数据库基础概念与数据建模全解析

本文深入解析了数据库的基础概念,包括函数依赖、决定因素和多值依赖等关键依赖关系,同时探讨了数据建模的重要方法论,如IDEF1X、信息工程和陈方法。此外,还介绍了SQL Server管理工作室的图表功能,帮助用户进行数据库的可视化设计。通过本文,读者将掌握数据库设计的核心知识,为构建高效、可扩展的数据库系统奠定基础。

82

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:支配边界构...

梦在哪里的博客 5605

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

codeforces 417A A. Elimination

A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The finalists of the "Russian Code Cup" compe

yjt9299的博客 350

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Java循环不变表达式外提_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:支配边界构...

weixin_39637979的博客 1015

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LLVM学习之OPT工具

1.概述 ELF文件是Linux中的目标文件。 分为: 可执行文件 可重定位文件(.o) 共享目标文件(.so)

weixin_42492218的博客 6048

LLVM全时优化

引子由于实验室项目原因,从本科开始接触Clang和LLVM开始到现在已经有2年时间了,期间都是针对Clang做一些边边角角的工作,没有潜下心来好好研读一下LLVM的paper。最近闲下来读了Chris Lattner那篇引用率高达2227的论文《LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation》,

电影旅行敲代码 9572

Codeforces 417A Elimination(水题)

题目链接:Codeforces 417A Elimination 题目大意:

不慌不忙、不急不躁 1524

CodeForces - 417A(思维题)

Elimination Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u SubmitStatus Description The finalists of the "Russian Code Cup" competition i...

weixin_30908649的博客 218

[CSA] Number Elimination

Solution 要求最小代价的方案数,所以我们显然可以直接把这些元素从小到大排序 我们令\(f_i\)表示消去\(i\)个一样的数字的方案数,不难得出\(f_i = \frac {i \cdot (i - 1)} {2} f_{i - 1}\) 假设当前有\(i\)个数字,我们可以任选两个数字把编号小的消去,所以方案数为\(i \choose 2\) 然后就转化成\(i - 1\)个数字的局面...

weixin_30808693的博客 196

Elimination(DP)

The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the

码农的一亩三分地 497

codeforces 859A Declined Finalists

A. Declined Finalists time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output This year, as in previous years, MemS

shyoldman的博客 873

Advanced Topics in Redundant Load Elimination with a Focus on PHI Translation

Saturday, December 19, 2009 Advanced Topics in Redundant Load Elimination with a Focus on PHI Translation In our previous post on GVN we introduced some basics of load elimination. This post describe...

ronnie88597的博客 884

GVARUSL--上海

一个字就是干净 线条 前景 正中间 又是这个技巧,人处于两条线之间 有掩体 线条也很完美 三角形

weixin_42907150的博客 273
上一篇: Intro to the LLVM MC Project
下一篇: libc++ and C++1Y
「已注销」
博客等级 码龄11年 2粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值