This is an archive of the discontinued LLVM Phabricator instance.

[LoopFlatten] Fix assertion failure
ClosedPublic

Authored by RosieSumpter on Aug 10 2021, 2:21 AM.

Details

Summary

There is an assertion failure in computeOverflowForUnsignedMul
(used in checkOverflow) due to the inner and outer trip counts
having different types. This occurs when the IV has been widened,
but the loop components are not successfully rediscovered.
This is fixed by some refactoring of the code in findLoopComponents
which identifies the trip count of the loop.

Diff Detail

Event Timeline

RosieSumpter created this revision.Aug 10 2021, 2:21 AM
RosieSumpter requested review of this revision.Aug 10 2021, 2:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2021, 2:21 AM

Added else statement with BackedgeTCExt = nullptr to prevent uninitialised value being used

SjoerdMeijer added inline comments.Aug 11 2021, 5:26 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
179

This has become quite complicated logic. I am wondering if we can handle the simple case first to reduce indentation and improve readability:

if (SCEVRHS == SCEVTripCount)
  return setLoopComponents(RHS, Increment);

where setLoopComponents is a new helper that includes the code at lines 229 - 233 and sets TripCount.

194

Remove this else and just initialise BackedgeTCExt above?

const SCEV *BackedgeTCExt = nullptr;
229

Then we can replace next lines with:

return setLoopComponents(RHS, Increment);
Added a helper function setLoopComponent to set the trip count
RosieSumpter marked an inline comment as done.Aug 12 2021, 2:40 AM
RosieSumpter added inline comments.
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
179

I've added a helper - hopefully it's what you had in mind, but I'm happy to change it if not

SjoerdMeijer added inline comments.Aug 12 2021, 3:57 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
97

Nit: perhaps rename RHS to TC so that it's a bit more descriptive.

99

Nit: don't think this comment adds much, and don't mind if you delete it. I think the function is small and its name descriptive enough.

179

Thanks, that's exactly what I had in mind.

I just added a few nits here and there, while I am going to take your patch now and run testing.

181

Nit: I think we can get rid of the else now.

Renamed 'RHS' to 'TC' in setLoopComponents and removed redundant else statements

RosieSumpter marked 4 inline comments as done.Aug 12 2021, 5:08 AM
SjoerdMeijer accepted this revision.Aug 12 2021, 8:38 AM

I've run our downstream benchmarks, and that came back green.

So this looks like a good fix to me.

This revision is now accepted and ready to land.Aug 12 2021, 8:38 AM