<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65629>65629</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AMDGPU] The `__builtin_round` intrinsic does not preserve `-0.0`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AMDGPU,
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
arsenm
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
The standard states the following about the behavior of the `round` functoin:
> If the implementation supports IEEE floating-point arithmetic (IEC 60559), for the std::round function:
> * If num is ±0, it is returned, unmodified
This is currently not respected by the AMDGPU implementation of `__builtin_round`. See the following reproducer for an example.
```c
#include <assert.h>
#include <math.h>
#include <stdio.h>
int main() {
double r;
double in = -0.0;
#pragma omp target map(from : r)
{ r = __builtin_round(in); }
assert(signbit(r) && "Result is no longer negative");
}
```
```shell
$ clang round.c -fopenmp --offload-arch=gfx1030 -fopenmp-offload-mandatory
$ ./a.out
a.out: round.c:10: int main(): Assertion `signbit(r) && "Result is no longer negative"' failed.
[1] 316479 IOT instruction (core dumped) ./a.out
$ clang round.c -fopenmp --offload-arch=sm_89 -fopenmp-offload-mandatory
$ ./a.out
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE2P4zYM_TXMhUigSLFjH3JIJkkxh6JFOz0PZJu2tZUlQx-zO_--kJzMtGl72AUCRyKlR_KRetJ7NRiiAxQn4Fw6T2YCzqE4r2QMo3WHL2NsyJWrxnbvh5eR0AdpOum6tAjkMYyEvdXaflVmQNnYGLKtoVG-KevQ9nkPJXM2mg5Khn00bbDKgDgCOwM7grjg83JOTbOmiUyQQVmDPs6zdcHj8-VywV5bGZQZ1rNVJqB0KowTBdUi8Or58oQlK4oaeA38CXvrMqIPXQokjjn-ElzZFBw_oyMCP6YcTJxQeYQnDqctSzgqJIOjEJ2hLlmimWynekXdHSF_X0bl09E2Okcm6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