<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63079>63079</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Fused multiply-add depends on constancy of expression arguments
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
As far as I know, Clang since version 14 applies fused multiply add (FMA) instructions even for constant computations performed at compile-time.
At the same time, one can observe that the result depends on formal constancy of expression arguments:
```
#include <stdio.h>
int main() {
const float A = 2.1f;
const float B = 0.1f;
float C = 0.1f;
float V = A * B - A * B;
float W = A * C - A * C;
printf( "%g %g", V, W );
}
```
In Clang the program prints `0 1.49011e-10`, online demo: https://godbolt.org/z/a3fcYG7ob
>From the assembly code, it can be seen that both `V` and `W` are evaluated in compile-time. Is there some rule that dictates that only `W` can be evaluated using FMA instruction?
Adding `-mno-fma` command line option for disabling FMA instruction does not change anything in the result.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVM9zqzgM_mvMRZOMMYWEAweaLjs9vGs7ezRYgHf9g7FMd7N__Q4mbdM33XmZjCOiT9KH9UmSSE8OsWHlIyufMrnG2YemQxWy3qtr0xKMMoAkeIa_nP-biQtcjHQTkHYDwhsG0t5B_gByWYxGgnElVGBXE_ViriCVAibO3Y-WiRq0oxjWIWrvCPANHYw-wOAdRekiDN4ua5S7e8Ew-mBRgdw92uAhaotHxp8Yb_ezjRBnBJIWYXNuDL1DGKQD3xOGN4Q4yx0VkFYTQeGCThH4VN5K885guIIfAf9ZAlJ6Lxmm1aKLxIpbPVbx23d_FIV2g1kVAisuFJX2x5kVv91T1C6Cldoxcd7ugJ0e9_8BYC8Mo_EyQguseAJxzEdW_A_kMUH4z5D9s0Mu30N250tytsBEC49weLc-kTvs9Q52-YBdviRcgnZxZOIMTAgmygm2I9kXeNmOV2Ci_ohhp6dvb_DZ3RS1NWgJfgrS7skJWMU55MeHmuc5HvIUlPprtENQaD0rWphjXFKDRMdEN3nVexOPPkxMdP8y0cliHP74_eT7-6Z0wdtUUhKh7c0VBq-SenRM4ukRCNHt4ul9nDc2L6ziIJ3a7NdkBwR8k2aVERVo91Wo8ExbjYBA3iKE1dzEqPQQZUTan7wz14-Mt9qfSVfSboLuR3s_PazovkyBUhuIVfxgnT-MVqZU3tqNbLotv2xxad6UJtmbb7KC8kjgfIRhlm5CkO4a5w2o3d0A3QYwU02h6qKWGTZ5dS5P4lxWIpsbVdYDr2Sd80qNp7Gq5CkXVYUlz-viXBaZbgQXBa-4yE9lxcWxVKqosKxLXp97wSv2wNFKbY7GvNmtlZkmWrGpCn6qMyN7NPS-tEKzgQ79OhF74EZTpM-wqKPBpvuykw7bTrrbAb8c_mwNpvlJZTrOa38cvGWi26rdfg5L8H_iEJnoEmNiokuk_wsAAP__goKtHw">