<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78825>78825</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang is sometimes suboptimal for `copysign(x, y)` when the sign of y is known
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Test case:
https://godbolt.org/z/6hjYTvjW8
```c
#include <math.h>
float f(float x)
{
return copysignf(1.0f, x * x);
}
float g(float x)
{
return (x > 0.0f) ? copysignf(1.0f, x) : 1.0f;
}
```
If `-ffast-math` is specified, clang can optimize `f`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsUs2OqzwMfRqzsYqCw--CRecH6duP9OkuAySQTiAVCdN2nv4q0GruvTMSghjH5_gcWzinh1nKGrInyF4isfrRLvX7QSyLvbiotf2tfpPOYyecBH4E9gLsOHp_diGiBqgZbN9a42O7DEDNJ1CTj6dfbx-n_8v9OuRsf7p7TFzPnVl7icCfJ-HHeAT-ek9ub2Ws8KiAyv10Baru-eIJEXEPwgkX6ddlxs6eb0FNKEpipoCe8YpAx72YP-ED4OU70_AXE35RfecBKq8I_BXZRlIh8OZn8j15xO3HD_wPW_5s5z-FkLODUsL5Q7AGcobaoTvLTist-4DcGTEP2IkZ7dnrSX_KUKQgZ3HU17yveCUiWScFy4okLYhHY92nVVsWWd4mPa8oSUlULK2oZXnJZNWzSNfEKGUJMZbwMuVxJoRQWa6I5dRKlkHK5CS0iY35mMK0I-3cKuuiLCmLjGilcdsiEW0NAlHYqaUO9w_tOjhImdHOuy8Er72R9a4nqLST9HqSDt3abtqEQWWXIO9hcfA_mHALU80ZXkY5ox8lhiRahbeA9D7byxyti6n_WVbtx7WNOzsBNaGN--dwXuxJdh6o2VQ5oGYT9jsAAP__SgjopA">