1、选项-ffp-contract=style (floating point expression contract)控制FMA特性,即fused multipy add。 fma的特点是可以使得这种模式的浮点计算更快精度更高
参考gcc优化选项解析 - PhoenixTree(梧桐树) - 博客园
2、性能和精度的权衡在于牛顿迭代步长的选取,参考⚙ D46498 [X86] Enable reciprocal estimates for v16f32 vectors by using VRCP14PS/VRSQRT14PS
注意:可以使用getRecipEstimateForFunc解析类似如下的attribute属性,只有存在类似attribute属性时才允许做Convert (fadd (fdiv y, z), x) -> fma(y, 1/z, x)转换,避免精度问题
attributes #0 = { norecurse nounwind "reciprocal-estimates"="vec-divf" }
3、 intel 在clang上传了一个精度相关的commit f04e387, 在这之前默认浮点是不能做交换,也就是下面两个表达式的结果可能不一样。此patch调整默认-ffp-contract=on,从而允许做交换,精度可能存在不一致。Compiler Explorer
b[i] += a[i] * d[i] + a[i+1] * d[i+1];
b[i] += a[i+1] * d[i+1] + a[i] * d[i];