<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155119>155119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-fexcess-precision=standard does not limit precision of x87 math
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mstorsjo
</td>
</tr>
</table>
<pre>
According to the documentation, x87 math should have the precision limited to the nominal precision of the type:
https://clang.llvm.org/docs/UsersManual.html
> For example, even on pre-SSE X86 targets where `float` and `double` computations must be performed in the 80-bit X87 format, Clang rounds all intermediate results correctly for their type.
Despite this, for a test function like this, the full x87 precision is retained even if both intermediates are assigned to float types (the same also holds if using explicit casts).
```c
int math(float a, float b, float c) {
float prod = a * b;
float sum = prod + c;
return (int)sum;
}
```
```
$ clang --target=i686-linux-gnu -mno-sse -O2 -fexcess-precision=standard math.c -S -o -
```
This differs from GCC, where `-fexcess-precision=standard` does limit the precision to the nominal precision of type type - see https://godbolt.org/z/arMsje11T. Here, GCC produces
```
fstp DWORD PTR [esp]
fld DWORD PTR [esp]
```
after both the multiplication and the addition, while Clang does nothing to limit the intermediate precision.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VE1v4zYQ_TX0ZSBDpvwhHXRI7PX2sthik6J7pciRxZQiBQ6ZTfrrC1JKnKSLGAZEcYbDeU_vjSDSF4vYst0t251WIobB-Xak4Dw9uFXn1HN7I6XzStsLBAdhQFBOxhFtEEE7y_gRnuoDjCIMQIOLRsEgHjFnTh6lJu0sGD3qgOqlhHWjtsK8SXB9DoTnCVl1w8r0H0KYKL3xM-NnaYS9rI15HNfOXxg_KyeJ8fNfhJ6-CRuFWQ9hNPNZVn2Bs_OAT2KcDKY28REtOJsuLe7uvsDPeg9B-AsGgl8DegS2L3vjRGD7EoRV6V252BlMG9KNU5xBE4yRAnQIE_re-REVaJsB1GXR6QA_6wOkg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