<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55230>55230</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[PPC] Compiler-rt builtins call fma in nostdlib soft floating point mode
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vit9696
</td>
</tr>
</table>
<pre>
Starting with llvm 14.0.0 there is a regression in PowerPC backend due to compiler-rt code resulting in libc function calls regardless of the `-nostdlib` / `-ffreestanding` flags.
One such example is `__fixunsdfdi` (compiler-rt/lib/builtins/fixunsdfdi.c), which is implemented as follows:
```C
COMPILER_RT_ABI du_int __fixunsdfdi(double a) {
if (a <= 0.0)
return 0;
su_int high = a / 4294967296.f; // a / 0x1p32f;
su_int low = a - (double)high * 4294967296.f; // high * 0x1p32f;
return ((du_int)high << 32) | low;
}
```
The problematic part can be shortened to the following code snippet:
```C
unsigned func(double a, double high) {
return a - high * 4294967296.f;
}
```
Upon compiling with `clang -O3 -target powerpc-gnu-linux -msoft-float -mcpu=e500mc -O3 -nostdlib` the following code is generated:
```
func(double, double): # @func(double, double)
mflr 0
stw 0, 4(1)
stwu 1, -16(1)
mr 7, 6
mr 8, 5
mr 9, 4
mr 10, 3
lis 5, -15888
li 6, 0
mr 3, 8
mr 4, 7
mr 7, 10
mr 8, 9
bl fma
bl __fixunsdfsi
lwz 0, 20(1)
addi 1, 1, 16
mtlr 0
blr
```
`fma` is not a function provided by compiler-rt builtins and thus should not be generated here. There is no issue with 13.0.1:
```
func(double, double): # @func(double, double)
mflr 0
stw 0, 4(1)
stwu 1, -32(1)
mr 7, 6
mr 8, 5
stw 29, 20(1) # 4-byte Folded Spill
mr 29, 3
stw 30, 24(1) # 4-byte Folded Spill
mr 30, 4
lis 5, -15888
li 6, 0
mr 3, 8
mr 4, 7
bl __muldf3
mr 5, 3
mr 6, 4
mr 3, 29
mr 4, 30
bl __adddf3
bl __fixunsdfsi
lwz 30, 24(1) # 4-byte Folded Reload
lwz 29, 20(1) # 4-byte Folded Reload
lwz 0, 36(1)
addi 1, 1, 32
mtlr 0
blr
```
CC @tstellar, this may need to be fixed in some 14.0.x release.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdV1tvqzgQ_jXkZUQEGEh4yENLt9KRdtWqp_scGTCJd81F2DTt_vqdsVPaJLTnSD3ah0UVAcb-5vPcW3TVy-a74YOR7Q4O0uxBqacGwngZLAMwezEIkBo4DGI3CK1l14Js4b47iOE-h4KXf4u2gmoUYDoou6aXSgz-YPC5ErhLj8pi4yYlixLqsS0NoZRcKU2wfKgUIkNXkz7w0sBvO20qXI7P4EW39ltdD0Jow9sK4UhQK77TSy-48YIrd79rBeix3IN45k2vLHNcud3W8nlsdVVX0iGu3xFFfNIU3RajJKoaH9_WL0svyrwoh8NeIjACSkJuRGtEBVxD3SnVHbTHrt4zQTXuL3fv-d0f999-_-1h-_C4vbr-hvbaytbACbNoXXVjgaw5qgRvde22AsiaKHPwWO6xG0DHEKejENCEZhxaCDw27dAOfi93e6At3FoxjrI4S1dRli5rXAynF66gRW5p8Bz2LKovIfGsR0QfJsZIx6mKri6UHGEn-SXykT-iEaBVMwHSiXNgkbNITuqnnd7q5szY7z3wiKHUDx2ya7iRJfScYpK3UGCM7LvBiBYdiDFLMeecSGFqo1a3su-FefPpmTfRY3JH2ymYT_yWw_GZ6J-5cTop2e4je_3M0f7sKX1sBE9Zi0tKxfHNv2PgY0LvhIGesrQv_V07-rh0fAa_0V1t_Fp13OBL2Y_oTJEEQVO6ne8zb8YyGP87NNzAMfo_Cnn3emKaN8NQ5LIr-PTyIgZeHHyCMFmUrqZWAwSn37Q54CfcEyNCeLEFxSOEJPfDdHZFM7jfFS1K52VrkiXzsswpn5WFlhk7FSo0beIYJev1-lyIHFAWzAMykq3nZTHJVp8cLvwA1J7uzCqFgrrhF9_eypiWZ8QP_zg_RM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