This is an archive of the discontinued LLVM Phabricator instance.

Fix incorrect TypeSize->uint64_t cast in InductionDescriptor::isInductionPHI
ClosedPublic

Authored by david-arm on Feb 1 2022, 5:24 AM.

Details

Summary

The code was relying upon the implicit conversion of TypeSize to
uint64_t and assuming the type in question was always fixed. However,
I discovered an issue when running the canon-freeze pass with some
IR loops that contains scalable vector types. I've changed the code
to bail out if the size is unknown at compile time, since we cannot
compute whether the step is a multiple of the type size or not.

I added a test here:

Transforms/CanonicalizeFreezeInLoops/phis.ll

Diff Detail

Event Timeline

david-arm created this revision.Feb 1 2022, 5:24 AM
david-arm requested review of this revision.Feb 1 2022, 5:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2022, 5:24 AM
CarolineConcatto accepted this revision.Feb 1 2022, 5:40 AM

It looks like a sensible patch.
I don't see a reason why it should not be approved as it is.

This revision is now accepted and ready to land.Feb 1 2022, 5:40 AM

The static_cast to int64_t was indeed incorrect and bailing out seems the right thing to do.

I think it's worth adding a test to llvm/unittests/Analysis/IVDescriptorsTest.cpp as well and testing the call to isInductionPHI explicitly.

david-arm updated this revision to Diff 406414.Feb 7 2022, 5:54 AM
  • Added a unit test!
sdesmalen accepted this revision.Feb 9 2022, 6:02 AM

LGTM with comments addressed.

llvm/lib/Analysis/IVDescriptors.cpp
1432

nit: I think this case could be supported, although that would require more work. Maybe you can leave a comment to say why we bail out for scalable vectors, and suggest there may be more work we can do here.

llvm/test/Transforms/CanonicalizeFreezeInLoops/phis.ll
116 ↗(On Diff #406414)

This test can probably be removed now? I don't think testing the code for this specific pass serves any specific purpose now that you've got the unittest.

This revision was landed with ongoing or failed builds.Feb 10 2022, 1:39 AM
This revision was automatically updated to reflect the committed changes.