<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109396>109396</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Floating-point constant to unsigned integer error
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bmq7911
</td>
</tr>
</table>
<pre>
When using clang (-O3) to convert a floating point constant such as -1234.56 into an unsigned integer and then printing out the converted result with printf, it produces a random value; whereas when using gcc(-O3) it outputs 0 instead.
```
#include <stdio.h>
int main(int argc, char * argv[]) {
float x = -1234.56;
unsigned int res = (unsigned int)x;
printf("res: %u\n", res);
return 0;
}
```
I have observed that when optimizing with -O3 flag, constant folding occurs during the EarlyCSE pass. However, during conversion within IEEEFloat module fails and results in oplnvalidOp which causes the conversion result to become poison. As a consequence of this poisoned parameter being passed through esi register according to x64 ABI standard rules , there exists an IMPLICIT_DEF statement assigning a value to rsi register which gets removed later on during processimpdefs pass leading ultimately leads producing random values being printed by printf function call . Do you know if there are any solutions available for this issue?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVMuu4zYM_RplQyRw5Ly88OLePNAALW6BFuiyoCXGVitLHj2Sm359QTuZybQDJLBNUeTh4SExRtM6olqs38X6MMOcOh_qpv-yrZbLWeP1vf6jIwc5GteCsuhaEHI3_yiFrCB5UN5dKSRAuFiPib0Gb1zig5jQJYhZdYAR5ktZrhbrDRiXPKCD7Mbkmg3UUgB0GhJnG4JxYyifE1ueWUhDoJhtgptJ3eR2EXIPJsEQvM6KIiAEdNr3cEWbSZTvcOsoEEZ-PitplfpWhkmcaMgpQgHGxUSoF6I4iOJNbIrHb_qUpXHKZk0gyn1M2vhFJ8rjdMpl92ickDt-xdAqBqc6DCDkGxuuE9GcVWzfp2sAMJEHnyDKw1eiRPni8EoWkzB6Crl7tQtZfX536UnQTkgZKIryDYRcZ7HeOy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