<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61130>61130</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Wasm] likely incorrect optimization of fp-int-fp conversion with fsz
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          malcom
      </td>
    </tr>
</table>

<pre>
    With `fno-signed-zeros` optimization enabled, the `fptosi/sitofp` and `fptoui/uitofp` roundtrip (fp-int-fp) is emitted as simple wasm `f64.trunc` instruction, even when a type with size less than f64 is used between conversions. This leads to unexpected results, always return orginal value without fraction part.

For example:
```llvm
define double @test(double %d) {
        %n = fptosi double %d to i32    ; c: int n = (int)d;
        %o = sitofp i32 %n to double    ; c: double o = (double)n;
        ret double %o
}
```

emits:
```wasm
test:
        .functype       test (f64) -> (f64)
        local.get       0
        f64.trunc
        end_function
```

return:
```
test(123.123)           // 123.0
test(9876543210.123)    // 9876543210.0
```

I would expect a value of `-2147483648.0`, as the standalone `ftopsi` operation return during overflow conversion on wasm (and other platforms) or at least some other value not exceeding 32 bits in this case.

I know, overflow in fp-int conversion is undefined behavior, so should this issue also be considered as UB or fsz optimization bug?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VcuO47YS_Rp6U7AgUQ9LCy-mb18D2SeYZUCJJYsZihRYJXu6vz4g5XarM0gAwYbreap06lgRmatDPIv6RdSvB7Xy5MN5Vnbw86H3-u383fAEoslH548pWB_fMXgSTQ5-YTObd8XGO0CneotayP8BT5hSFvZkhLyQYT8uMUM5_eFZo2d9eoJfneZgFhCyHZejcXwcFyE7MAQ4G2bUoAjIzItFuCuaU6Wmyjisbog1jCMO6xDhRBh4Qwf3CR0o4LcF4R5nIfOOYJEIeFIOxqaKHVZCDT3yHdHB4N0NAxnvKIPfJ0NgUWkC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