Hasty Briefsbeta

双语

Tracking down a 25% Regression on LLVM RISC-V

4 days ago
  • #Performance Optimization
  • #RISC-V
  • #LLVM
  • 一个LLVM提交改进了isKnownExactCastIntToFP函数,使得fpext(sitofp x到float)到double的优化可转化为uitofp x到double,但意外破坏了visitFPTrunc中的下游缩小优化。
  • 这导致RISC-V目标出现约24%的性能衰退,因为生成了fdiv.d(33周期延迟)而非fdiv.s(19周期延迟)。
  • 修复方案通过范围分析扩展了getMinimumFPType功能,使其能识别fptrunc(uitofp x double)到float可简化为uitofp x到float,从而恢复了缩小优化。
  • 分析发现性能衰退出现在某个基准测试中,该场景下LLVM在循环中使用fdiv.d,而GCC使用fdiv.s,导致周期数增加。
  • 该问题可追溯至InstCombine模块的特定提交,该提交改变了isKnownExactCastIntToFP的行为,阻碍了visitFPTrunc进行double到float的缩小优化。
  • 已提交并合并补丁,修改了canBeCastedExactlyIntToFP和getMinimumFPType函数以支持带fptrunc的整型到浮点型转换优化,最终实现浮点运算优化和性能恢复。