This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] try to convert sitofp to uitofp
AbandonedPublic

Authored by spatel on Sep 30 2022, 11:00 AM.

Details

Summary

https://alive2.llvm.org/ce/z/tDmLfs

This is another small extension of the signed->unsigned logic. This can enable subsequent FP folds because it eliminates negative FP values. Example:
https://alive2.llvm.org/ce/z/tnwfVk

Codegen can invert the transform if it can see that the input signbit is clear.

There was a comment on a test saying not to try this, but I don't see a reason to avoid it. I adjusted one of the existing tests to show that we are not miscompiling when the range includes a negative value.

Diff Detail

Event Timeline

spatel created this revision.Sep 30 2022, 11:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2022, 11:00 AM
spatel requested review of this revision.Sep 30 2022, 11:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2022, 11:00 AM
spatel edited the summary of this revision. (Show Details)Sep 30 2022, 11:02 AM
nikic accepted this revision.Sep 30 2022, 11:50 AM

LGTM

This revision is now accepted and ready to land.Sep 30 2022, 11:50 AM

uitofp is significantly more expensive than sitofp on many targets. I'm not sure we want to do this if we're not confident we can reverse the transform.

spatel abandoned this revision.Sep 30 2022, 12:58 PM

uitofp is significantly more expensive than sitofp on many targets. I'm not sure we want to do this if we're not confident we can reverse the transform.

Yes, this has potential to find transforms that SDAG can't recover since it's looking across blocks.
I don't have a real example where this comes into play; just noticed that we'd need an extra condition for signed cast with an fmul fold as in the example.
SDAG already tries to convert these in both directions after testing legality, so that's probably good enough. I'll put a code comment in SCCP and abandon this patch.