As shown in https://github.com/llvm/llvm-project/issues/55150 - the existing fold may be wrong when converting to a signed value.
This is a quick fix to avoid the miscompile.
I added tests/comments for all of the signed/unsigned combinations at the border width, and tried to confirm with Alive2:
https://alive2.llvm.org/ce/z/3p9DSu
There are already some TODO items in the test file that suggest possible refinements, so the regression with ui->FP->si is probably ok? It seems unlikely that we'd see these kind of edge cases with non-byte width integer types in real code. The potential miscompile went undetected for several years.