LLVM 编译器学习笔记之六十七 -- 浮点优化-ffast-math

1、-ffast-math 包括一系列的子优化特性(对应fast属性),预期该选项能得到最好的性能,参考

https://llvm.org/docs/LangRef.html#fast-math-flags

-fno-honor-infinities
-fno-honor-nans
-fno-math-errno
-ffinite-math
-fassociative-math
-freciprocal-math
-fno-signed-zeros
-fno-trapping-math
-ffp-contract=fast ,对应contract属性,而不是fast

 2、只有选项-ffast-math使能情况下,才允许对浮点的访存操作向量化,否则提示unsafe algebra

3、一些特别的分析[InstCombine] optimize powi(X,Y)/X with Ofast by vfdff · Pull Request #67236 · llvm/llvm-project · GitHub

 reassoc is the general flag we've been using for pow combines, so that checks out.

Special case analysis:

  • X is nonspecial, Y is INT_MIN -> result should be +/-0, Y wraparound produces +/-infinity instead

  • X is +/-0, Y is INT_MIN -> result should be +/-infinity, Y wraparound produces +/-0 instead

  • X is +/-inf, Y is INT_MIN -> result should be +/-0, Y wraparound produces +/-infinity instead

  • X is NaN, Y is INT_MIN -> result should be NaN, wraparound produces NaN

  • X is NaN, Y is not 1 -> result should be NaN, transform is correct

  • X is NaN, Y is 1 -> result should be NaN, transform makes it 1 instead

  • X is +/- 0, Y > 1 -> result should be NaN, transform makes it +/- 0 instead

  • X is +/- 0, Y is 1 -> result should be NaN, transform makes it 1 instead

  • X is +/- 0, Y is 0 -> result should be +/-inf, transform is correct

  • X is +/- 0, Y < 0 -> result should be inf, transform is correct

  • X is +/- inf, Y > 1 -> result should be NaN, transform makes it +/-inf instead

  • X is +/- inf, Y is 1 -> result should be NaN, transform makes it 1 instead

  • X is +/- inf, Y is 0 -> result should be +/-0, transform is correct

  • X is +/- inf, Y < 0 -> result should be +/-0, transform is correct

(assuming powi(X, 1) is exactly X and powi(X, -1) is exactly 1.0/X)

  • X is nonspecial, Y is 1 -> result should be 1, transform is correct
  • X is nonspecial, Y is 0 -> result should be 1/x, transform is correct

Ignoring the issue of INT_MIN - 1 wraparound, the cases where the transformation is incorrect is when the result would have been NaN (largely via intermediate 0.0/0.0 or infinity/infinity), so nnan is sufficient for that case. Taking into account the potential for wraparound, however, there is no set of fast-math flags that makes the transformation legal: powi(2.0, INT_MIN) is 0.0, and 0.0/2.0 is legally 0.0.

4、fastmath的详细介绍,参考https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math 

nnan, ninf, and poison - #2 by rotateright - LLVM Dev List Archives - LLVM Discussion Forums

5、float_control(precise) 可以设置某个区间的代码有特别的优化要求

pragma float_control - Intel Community

Propogation of fpclass assumptions vis a vis fast-math flags - #2 by efriedma-quic - IR & Optimizations - LLVM Discussion Forums

6、创建IR 时Builder.setFastMathFlags设置fast, 则新创建的每个IR均带有fast属性commit 92057604

7、RP63476:fp-contract=fast => fmul contract + fadd contract. fp-contract=on => fmuladd

8、pragma 也可以指示fast属性,参考https://github.com/llvm/llvm-project/pull/90377

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: LLVM是一个模块化化和可重用的编译器和工具链技术的集合,它支持多种编程语言如C,C++,Objective-C等,并且可以运行于多个平台上。LLVM-16.0.0-win64.exe是一个针对Windows 64位操作系统的LLVM编译器工具包。它可以提供丰富的编译优化和代码生成功能,包括静态分析、调试支持和各种优化技术。在该工具包中包含了LLVM Clang编译器LLVM LLD链接器、LLVM lldb调试器和相关的辅助工具,这些工具可以帮助开发者更好地构建高效、高性能的应用程序。此外,LLVM-16.0.0-win64.exe还提供了开发编译自己的C/C++应用程序所需的各种库、头文件和文档等支持。总体来说,LLVM-16.0.0-win64.exe是一款强大的编译器工具包,可以使Windows 64位平台上的开发者更加轻松、高效地进行编译开发工作。 ### 回答2: llvm是一个编译器和工具链基础设施的开源项目。llvm-16.0.0-win64.exe是一个用于Windows 64位操作系统的llvm编译器安装程序。它包含了llvm编译器、调试器、汇编器、链接器等工具,并提供了对C、C++、Objective-C、Fortran等语言的支持。该版本的llvm-16.0.0-win64.exe新增了许多新特性和改进,包括对WebAssembly的支持、更好的LLDB使⽤和调试体验,以及对新版CPU的运⾏时支持。使用llvm编译器可以使您的程序获得更好的性能和稳定性,同时操作系统和硬件平台也获得更好的兼容性。如果您需要在Windows 64位操作系统上编译、调试或优化程序,llvm-16.0.0-win64.exe是一个非常好的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值