This is an archive of the discontinued LLVM Phabricator instance.

[LoopFlatten] Bail if we can't perform flattening after IV widening
ClosedPublic

Authored by SjoerdMeijer on Sep 29 2021, 6:30 AM.

Details

Summary

It can happen that after widening of the IV, flattening may not be possible, e.g. when it is deemed unprofitable. We were not properly checking this, which resulted in flattening being applied when it shouldn't.

This should fix PR51980 (https://bugs.llvm.org/show_bug.cgi?id=51980)

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Sep 29 2021, 6:30 AM
SjoerdMeijer requested review of this revision.Sep 29 2021, 6:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2021, 6:30 AM
dmgreen added inline comments.Sep 29 2021, 7:26 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
757–758

his -> this

764

I think false means "the code didn't change". But it will have had phi's widened so should be returning true?

SjoerdMeijer added inline comments.Sep 29 2021, 7:54 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
764

Hmmm.... interesting. So, yes, it makes a change, but not the one we were expecting, i.e. not the flattening (which is what this whole TODO is about). So I am not sure if we want or should be returning true, but given that it is making a code change, probably better to do so. I will change that.

Addressed comments.

dmgreen accepted this revision.Sep 29 2021, 10:23 AM

Thanks. LGTM

And I agree with the comment that it would be better to not widen if not necessary, but if this fixes a bug it looks good to me in the meantime.

This revision is now accepted and ready to land.Sep 29 2021, 10:23 AM

Thanks, and yes, I will see if we can make this part more robust and follow up on this.

This revision was landed with ongoing or failed builds.Sep 29 2021, 11:54 AM
This revision was automatically updated to reflect the committed changes.