This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Eliminate redundant type cast between unsigned integer and float
ClosedPublic

Authored by Allen on Jul 8 2022, 3:09 AM.

Details

Summary

Extend for unsigned integer according the comment of D129191.

Diff Detail

Event Timeline

Allen created this revision.Jul 8 2022, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 3:09 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Allen requested review of this revision.Jul 8 2022, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 3:09 AM
Allen edited the summary of this revision. (Show Details)Jul 11 2022, 6:24 AM
nikic added inline comments.Jul 12 2022, 6:24 AM
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
697

For fptoui, shouldn't we also check that it's non-negative? Wouldn't your current code optimize an IV that does -100 to 100 for example?

Allen added inline comments.Jul 12 2022, 8:05 AM
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
697

thanks @nikic very much, and I verified that the gcc also transform with negative value, see detail in https://godbolt.org/z/1hxebdYfr

nikic accepted this revision.Jul 13 2022, 5:41 AM

LGTM

The next step here could be to also support uitofp.

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
697

Ah yes, it is fine because FPToUI with negative value results in poison anyway. It would probably still be valuable to add a test with negative IV.

This revision is now accepted and ready to land.Jul 13 2022, 5:41 AM
Allen updated this revision to Diff 444477.Jul 13 2022, 6:05 PM
Allen marked an inline comment as not done.

Add a new test case including negative value according comment

Allen marked 2 inline comments as done.Jul 13 2022, 6:07 PM
Allen added inline comments.
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
697

it doesn't have scvtf, also see the range (-100, 100] in https://godbolt.org/z/jMhxfnbs9

697

Done, thanks.

Allen updated this revision to Diff 444580.Jul 14 2022, 3:21 AM
Allen marked an inline comment as done.

update test case

This revision was landed with ongoing or failed builds.Jul 14 2022, 4:43 AM
This revision was automatically updated to reflect the committed changes.
Allen added a comment.Jul 14 2022, 4:58 AM

LGTM

The next step here could be to also support uitofp.

Thanks, addressed here, https://reviews.llvm.org/D129756.