<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64653>64653</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
pragma clang fp contract(fast) does not emit contract flags on calls compared to -ffp-contract=fast
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:codegen,
floating-point
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
arsenm
</td>
</tr>
</table>
<pre>
Enabling fast contract with the pragma misses setting contract flags in some contexts (at a minimum, seems to not apply to any call). They are set if you use the global command line flag.
```
// clang -fno-math-errno -x c -O3 -S -emit-llvm
// clang -fno-math-errno -ffp-contract=fast -x c -O3 -S -emit-llvm
#include <math.h>
float enable_contract_fast_basic_ops(float x, float y, float z){
#pragma clang fp contract(fast)
x *= y;
x += z;
x /= z;
return x;
}
// contract missing from sqrtf call with only the pragma
// contract is present when using -ffp-contract=fast
float enable_contract_fast_sqrt_call(float x, float y) {
#pragma clang fp contract(fast)
return x / sqrtf(y);
}
float enable_contract_fast_builtin_sqrt_call(float x, float y) {
#pragma clang fp contract(fast)
return x / __builtin_sqrtf(y);
}
```
For example in this last function, with only the pragma I see:
```
define dso_local float @enable_contract_fast_builtin_sqrt_call(float noundef %0, float noundef %1) local_unnamed_addr #1 {
%3 = tail call float @llvm.sqrt.f32(float %1) ; missing contract flag
%4 = fdiv contract float %0, %3
ret float %4
}
```
Using -ffp-contract=fast:
```
define dso_local float @enable_contract_fast_builtin_sqrt_call(float noundef %0, float noundef %1) local_unnamed_addr #1 {
%3 = tail call contract float @llvm.sqrt.f32(float %1) ; contract correctly set on everything
%4 = fdiv contract float %0, %3
ret float %4
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVkGP4yYU_jX48uTIgcRrH3yYmWyknnpoe46wedhUGFzAs8n--gqcZJLZdHeqSitVihL7Bb73-L6PB9x71RvEhmyfyXaX8TkM1jXceTRj1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