This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fix miscompile when casting int->FP->int
ClosedPublic

Authored by spatel on Apr 29 2022, 12:37 PM.

Details

Summary

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.

Diff Detail

Event Timeline

spatel created this revision.Apr 29 2022, 12:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 12:37 PM
spatel requested review of this revision.Apr 29 2022, 12:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 12:37 PM
spatel retitled this revision from [InstCombin] fix miscompile when casting int->FP->int to [InstCombine] fix miscompile when casting int->FP->int.Apr 29 2022, 12:39 PM

Does DAGCombiner have the same bug are will you be patching it too?

Does DAGCombiner have the same bug are will you be patching it too?

Sure - that part is in DAGCombiner::FoldIntToFPToInt() and looks similar.

spatel added a comment.May 6 2022, 4:56 AM

Ping. The SDAG sibling was pushed a few days ago with:
D124771 ( 747c6a0c734e618db )

This revision is now accepted and ready to land.May 6 2022, 12:03 PM
This revision was landed with ongoing or failed builds.May 7 2022, 5:50 AM
This revision was automatically updated to reflect the committed changes.
Allen added a subscriber: Allen.Jun 17 2022, 6:50 AM