This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Directly use unsigned integer induction for FPToUI/FPToSI of float induction
ClosedPublic

Authored by Allen on Jul 14 2022, 4:55 AM.

Diff Detail

Event Timeline

Allen created this revision.Jul 14 2022, 4:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 4:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Allen requested review of this revision.Jul 14 2022, 4:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 4:55 AM
nikic added a comment.Jul 14 2022, 5:19 AM

I think this is correct as written, but also confusing. It would make more sense to me if for fptoui we used getUnsignedRange() and getActiveBits() and for fptosi used getSignedRange() and getMinSignedBits().

llvm/test/Transforms/IndVarSimplify/floating-point-small-iv.ll
182

We should be testing negative ranges as well -- in this case, they would actually be not legal.

Allen added inline comments.Jul 14 2022, 5:44 AM
llvm/test/Transforms/IndVarSimplify/floating-point-small-iv.ll
182

for unsigned type induction, negative ranges will be determined true at very early pass, so we don't need check it ?
https://godbolt.org/z/rerdG58cj

Allen updated this revision to Diff 444624.Jul 14 2022, 5:58 AM

update according comment
fptoui we used getUnsignedRange() and getActiveBits()
fptosi used getSignedRange() and getMinSignedBits()

Allen added a comment.Jul 14 2022, 6:00 AM

I think this is correct as written, but also confusing. It would make more sense to me if for fptoui we used getUnsignedRange() and getActiveBits() and for fptosi used getSignedRange() and getMinSignedBits().

Done, thanks very much for your careful and patient guidance.

nikic accepted this revision.Jul 16 2022, 3:43 AM

LGTM

The last step here would be to deal with different sizes between the itofp and fptoi with trunc or sext/zext.

llvm/test/Transforms/IndVarSimplify/floating-point-small-iv.ll
182

Passes need to be correct in isolation, so I think it is important to still test that case here, even if it gets transformed earlier in the full pipeline.

This revision is now accepted and ready to land.Jul 16 2022, 3:43 AM
Allen updated this revision to Diff 445282.Jul 16 2022, 7:44 PM

Add two case with negative range

This revision was landed with ongoing or failed builds.Jul 16 2022, 7:51 PM
This revision was automatically updated to reflect the committed changes.
Allen marked 2 inline comments as done.Jul 16 2022, 7:55 PM
Allen added inline comments.
llvm/test/Transforms/IndVarSimplify/floating-point-small-iv.ll
182

Done, thanks