[PATCH] D124692: [InstCombin] fix miscompile when casting int->FP->int

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 12:37:09 PDT 2022


spatel created this revision.
spatel added reviewers: efriedma, regehr, nlopes.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D124692

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/sitofp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124692.426141.patch
Type: text/x-patch
Size: 3644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220429/d1b7a0e4/attachment.bin>


More information about the llvm-commits mailing list